+
+pk_dellink (pkp)
+register struct pkcb *pkp;
+{
+ register int i;
+ register struct protosw *pp;
+
+ /*
+ * Essentially we have the choice to
+ * (a) go ahead and let the route be deleted and
+ * leave the pkcb associated with that route
+ * as it is, i.e. the connections stay open
+ * (b) do a pk_disconnect() on all channels associated
+ * with the route via the pkcb and then proceed.
+ *
+ * For the time being we stick with (b)
+ */
+
+ for (i = 1; i < pkp -> pk_maxlcn; ++i)
+ if (pkp -> pk_chan[i])
+ pk_disconnect (pkp -> pk_chan[i]);
+
+ /*
+ * Free the pkcb
+ */
+
+ /*
+ * First find the protoswitch to get hold of the link level
+ * protocol to be notified that the packet level entity is
+ * dissolving ...
+ */
+ pp = pffindproto (AF_CCITT, (int) pkp -> pk_xcp -> xc_lproto, 0);
+ if (pp == 0 || pp -> pr_output == 0) {
+ pk_message (0, pkp -> pk_xcp, "link level protosw error");
+ return (EPROTONOSUPPORT);
+ }
+
+ pkp -> pk_refcount--;
+ if (!pkp -> pk_refcount) {
+ struct dll_ctlinfo ctlinfo;
+
+ remque (pkp);
+ if (pkp -> pk_rt -> rt_llinfo == (caddr_t) pkp)
+ pkp -> pk_rt -> rt_llinfo = (caddr_t) NULL;
+
+ /*
+ * Tell the link level that the pkcb is dissolving
+ */
+ if (pp -> pr_ctlinput && pkp -> pk_llnext) {
+ ctlinfo.dlcti_pcb = pkp -> pk_llnext;
+ ctlinfo.dlcti_rt = pkp -> pk_rt;
+ (pp -> pr_ctlinput)(PRC_DISCONNECT_REQUEST,
+ pkp -> pk_xcp, &ctlinfo);
+ }
+ free ((caddr_t) pkp -> pk_chan, M_IFADDR);
+ free ((caddr_t) pkp, M_PCB);
+ }
+
+ return (0);
+}
+
+