-struct pkcb *
-pk_newlink (xcp)
-struct x25config *xcp;
-{
- register struct pkcb *pkp;
- register struct mbuf *m;
- register struct pklcd *lcp;
- register struct protosw *pp;
- register unsigned size;
-
- if (xcp -> xc_ntnlen <= 0 || xcp -> xc_ntnlen > sizeof (xcp -> xc_ntn) * 2)
- return ((struct pkcb *)0);
-#ifdef BSD4_3
- pp = pffindproto (AF_CCITT, (int)xcp -> xc_lproto, 0);
-#else
- pp = pffindproto (AF_CCITT, (int)xcp -> xc_lproto);
-#endif
- if (pp == 0 || pp -> pr_output == 0) {
- pk_message (0, xcp, "link level protosw error");
- return ((struct pkcb *)0);
- }
-
- /*
- * Allocate a network control block structure
- */
-
- size = sizeof (struct pkcb) + xcp->xc_maxlcn * sizeof (struct pklcd *);
-#ifdef sun
- if (xcp -> xc_maxlcn < 1 || size > mclbytes) {
-#else
- if (xcp -> xc_maxlcn < 1 || size > CLBYTES) {
-#endif
- pk_message (0, xcp, "invalid maxlcn");
- return ((struct pkcb *)0);
- }
- m = m_get (M_DONTWAIT, MT_PCB);
- if (m == 0)
- return ((struct pkcb *)0);
- if (size > MLEN) {
-#ifdef sun
- if (mclget (m) == 0) {
- m_freem (m);
- return ((struct pkcb *)0);
- }
-#else
-#ifdef BSD4_3
- MCLGET (m);
- if (m -> m_len != CLBYTES) {
- (void) m_free (m);
- return ((struct pkcb *)0);
- }
-#else
- register struct mbuf *p;
-
- MCLGET (p, 1);
- if (p == 0) {
- m_freem (m);
- return ((struct pkcb *)0);
- }
- m -> m_off = (int)p - (int)m;
-#endif
-#endif
- }
- pkp = mtod (m, struct pkcb *);
- bzero ((caddr_t)pkp, size);
-
- /*
- * Allocate a logical channel descriptor for lcn 0
- */
-
- m = m_getclr (M_DONTWAIT, MT_PCB);
- if (m == 0) {
- m_freem (dtom (pkp));
- return ((struct pkcb *)0);
- }
- lcp = mtod (m, struct pklcd *);
- lcp -> lcd_state = READY;
- lcp -> lcd_pkp = pkp;
- pkp -> pk_chan[0] = lcp;
-
- pkp -> pk_output = pp -> pr_output;
- pkp -> pk_xcp = xcp;
- pkp -> pk_state = DTE_WAITING;
- pkp -> pk_maxlcn = xcp -> xc_maxlcn;
- pkp -> pk_next = pkcbhead;
- pkcbhead = pkp;
-
- /*
- * set defaults
- */
-
- if (xcp -> xc_pwsize == 0)
- xcp -> xc_pwsize = DEFAULT_WINDOW_SIZE;
- if (xcp -> xc_psize == 0)
- xcp -> xc_psize = X25_PS128;
- return (pkp);
-}
-