|
|
1.1 root 1: /*-
2: * Copyright (c) 1991 The Regents of the University of California.
3: * All rights reserved.
4: *
5: * Redistribution and use in source and binary forms, with or without
6: * modification, are permitted provided that the following conditions
7: * are met:
8: * 1. Redistributions of source code must retain the above copyright
9: * notice, this list of conditions and the following disclaimer.
10: * 2. Redistributions in binary form must reproduce the above copyright
11: * notice, this list of conditions and the following disclaimer in the
12: * documentation and/or other materials provided with the distribution.
13: * 3. All advertising materials mentioning features or use of this software
14: * must display the following acknowledgement:
15: * This product includes software developed by the University of
16: * California, Berkeley and its contributors.
17: * 4. Neither the name of the University nor the names of its contributors
18: * may be used to endorse or promote products derived from this software
19: * without specific prior written permission.
20: *
21: * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22: * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23: * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24: * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25: * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26: * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27: * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28: * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29: * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30: * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31: * SUCH DAMAGE.
32: *
1.1.1.2 ! root 33: * from: @(#)esis.c 7.19 (Berkeley) 6/27/91
! 34: * esis.c,v 1.2 1993/05/20 05:27:07 cgd Exp
1.1 root 35: */
36:
37: /***********************************************************
38: Copyright IBM Corporation 1987
39:
40: All Rights Reserved
41:
42: Permission to use, copy, modify, and distribute this software and its
43: documentation for any purpose and without fee is hereby granted,
44: provided that the above copyright notice appear in all copies and that
45: both that copyright notice and this permission notice appear in
46: supporting documentation, and that the name of IBM not be
47: used in advertising or publicity pertaining to distribution of the
48: software without specific, written prior permission.
49:
50: IBM DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
51: ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
52: IBM BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
53: ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
54: WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
55: ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
56: SOFTWARE.
57:
58: ******************************************************************/
59:
60: /*
61: * ARGO Project, Computer Sciences Dept., University of Wisconsin - Madison
62: */
63:
64: #ifdef ISO
65:
66: #include "types.h"
67: #include "param.h"
68: #include "systm.h"
69: #include "mbuf.h"
70: #include "domain.h"
71: #include "protosw.h"
72: #include "socket.h"
73: #include "socketvar.h"
74: #include "errno.h"
75:
76: #include "../net/if.h"
77: #include "../net/if_dl.h"
78: #include "../net/route.h"
79: #include "../net/raw_cb.h"
80:
81: #include "iso.h"
82: #include "iso_pcb.h"
83: #include "iso_var.h"
84: #include "iso_snpac.h"
85: #include "clnl.h"
86: #include "clnp.h"
87: #include "clnp_stat.h"
88: #include "esis.h"
89: #include "argo_debug.h"
90: #include "kernel.h"
91:
92: /*
93: * Global variables to esis implementation
94: *
95: * esis_holding_time - the holding time (sec) parameter for outgoing pdus
96: * esis_config_time - the frequency (sec) that hellos are generated
97: * esis_esconfig_time - suggested es configuration time placed in the
98: * ish.
99: *
100: */
101: struct rawcb esis_pcb;
102: int esis_config(), snpac_age();
103: int esis_sendspace = 2048;
104: int esis_recvspace = 2048;
105: short esis_holding_time = ESIS_HT;
106: short esis_config_time = ESIS_CONFIG;
107: short esis_esconfig_time = ESIS_CONFIG;
108: extern int iso_systype;
109: struct sockaddr_dl esis_dl = { sizeof(esis_dl), AF_LINK };
110: extern char all_es_snpa[], all_is_snpa[];
111:
112: #define EXTEND_PACKET(m, mhdr, cp)\
113: if (((m)->m_next = m_getclr(M_DONTWAIT, MT_HEADER)) == NULL) {\
114: esis_stat.es_nomem++;\
115: m_freem(mhdr);\
116: return;\
117: } else {\
118: (m) = (m)->m_next;\
119: (cp) = mtod((m), caddr_t);\
120: }
121: /*
122: * FUNCTION: esis_init
123: *
124: * PURPOSE: Initialize the kernel portion of esis protocol
125: *
126: * RETURNS: nothing
127: *
128: * SIDE EFFECTS:
129: *
130: * NOTES:
131: */
132: esis_init()
133: {
134: extern struct clnl_protosw clnl_protox[256];
135: int esis_input(), isis_input();
136: #ifdef ISO_X25ESIS
137: int x25esis_input();
138: #endif ISO_X25ESIS
139:
140: esis_pcb.rcb_next = esis_pcb.rcb_prev = &esis_pcb;
141: llinfo_llc.lc_next = llinfo_llc.lc_prev = &llinfo_llc;
142:
143: timeout(snpac_age, (caddr_t)0, hz);
144: timeout(esis_config, (caddr_t)0, hz);
145:
146: clnl_protox[ISO9542_ESIS].clnl_input = esis_input;
147: clnl_protox[ISO10589_ISIS].clnl_input = isis_input;
148: #ifdef ISO_X25ESIS
149: clnl_protox[ISO9542X25_ESIS].clnl_input = x25esis_input;
150: #endif ISO_X25ESIS
151: }
152:
153: /*
154: * FUNCTION: esis_usrreq
155: *
156: * PURPOSE: Handle user level esis requests
157: *
158: * RETURNS: 0 or appropriate errno
159: *
160: * SIDE EFFECTS:
161: *
162: */
163: /*ARGSUSED*/
164: esis_usrreq(so, req, m, nam, control)
165: struct socket *so; /* socket: used only to get to this code */
166: int req; /* request */
167: struct mbuf *m; /* data for request */
168: struct mbuf *nam; /* optional name */
169: struct mbuf *control; /* optional control */
170: {
171: struct rawcb *rp = sotorawcb(so);
172: int error = 0;
173:
174: if ((so->so_state & SS_PRIV) == 0) {
175: error = EACCES;
176: goto release;
177: }
178: if (rp == NULL && req != PRU_ATTACH) {
179: error = EINVAL;
180: goto release;
181: }
182:
183: switch (req) {
184: case PRU_ATTACH:
185: if (rp != NULL) {
186: error = EINVAL;
187: break;
188: }
189: MALLOC(rp, struct rawcb *, sizeof(*rp), M_PCB, M_WAITOK);
190: if (so->so_pcb = (caddr_t)rp) {
191: bzero(so->so_pcb, sizeof(*rp));
192: insque(rp, &esis_pcb);
193: rp->rcb_socket = so;
194: error = soreserve(so, esis_sendspace, esis_recvspace);
195: } else
196: error = ENOBUFS;
197: break;
198:
199: case PRU_SEND:
200: if (nam == NULL) {
201: error = EINVAL;
202: break;
203: }
204: /* error checking here */
205: error = isis_output(mtod(nam,struct sockaddr_dl *), m);
206: m = NULL;
207: break;
208:
209: case PRU_DETACH:
210: raw_detach(rp);
211: break;
212:
213: case PRU_SHUTDOWN:
214: socantsendmore(so);
215: break;
216:
217: case PRU_ABORT:
218: soisdisconnected(so);
219: raw_detach(rp);
220: break;
221:
222: case PRU_SENSE:
223: return (0);
224:
225: default:
226: return (EOPNOTSUPP);
227: }
228: release:
229: if (m != NULL)
230: m_freem(m);
231:
232: return (error);
233: }
234:
235: /*
236: * FUNCTION: esis_input
237: *
238: * PURPOSE: Process an incoming esis packet
239: *
240: * RETURNS: nothing
241: *
242: * SIDE EFFECTS:
243: *
244: * NOTES:
245: */
246: esis_input(m0, shp)
247: struct mbuf *m0; /* ptr to first mbuf of pkt */
248: struct snpa_hdr *shp; /* subnetwork header */
249: {
250: register struct esis_fixed *pdu = mtod(m0, struct esis_fixed *);
251: register int type;
252:
253: /*
254: * check checksum if necessary
255: */
256: if (ESIS_CKSUM_REQUIRED(pdu) && iso_check_csum(m0, (int)pdu->esis_hdr_len)) {
257: esis_stat.es_badcsum++;
258: goto bad;
259: }
260:
261: /* check version */
262: if (pdu->esis_vers != ESIS_VERSION) {
263: esis_stat.es_badvers++;
264: goto bad;
265: }
266: type = pdu->esis_type & 0x1f;
267: switch (type) {
268: case ESIS_ESH:
269: esis_eshinput(m0, shp);
270: break;
271:
272: case ESIS_ISH:
273: esis_ishinput(m0, shp);
274: break;
275:
276: case ESIS_RD:
277: esis_rdinput(m0, shp);
278: break;
279:
280: default:
281: esis_stat.es_badtype++;
282: }
283:
284: bad:
285: if (esis_pcb.rcb_next != &esis_pcb)
286: isis_input(m0, shp);
287: else
288: m_freem(m0);
289: }
290:
291: /*
292: * FUNCTION: esis_rdoutput
293: *
294: * PURPOSE: Transmit a redirect pdu
295: *
296: * RETURNS: nothing
297: *
298: * SIDE EFFECTS:
299: *
300: * NOTES: Assumes there is enough space for fixed part of header,
301: * DA, BSNPA and NET in first mbuf.
302: */
303: esis_rdoutput(inbound_shp, inbound_m, inbound_oidx, rd_dstnsap, rt)
304: struct snpa_hdr *inbound_shp; /* snpa hdr from incoming packet */
305: struct mbuf *inbound_m; /* incoming pkt itself */
306: struct clnp_optidx *inbound_oidx; /* clnp options assoc with incoming pkt */
307: struct iso_addr *rd_dstnsap; /* ultimate destination of pkt */
308: struct rtentry *rt; /* snpa cache info regarding next hop of
309: pkt */
310: {
311: struct mbuf *m, *m0;
312: caddr_t cp;
313: struct esis_fixed *pdu;
314: int len, total_len = 0;
315: struct sockaddr_iso siso;
316: struct ifnet *ifp = inbound_shp->snh_ifp;
317: struct sockaddr_dl *sdl;
318: struct iso_addr *rd_gwnsap;
319:
320: if (rt->rt_flags & RTF_GATEWAY) {
321: rd_gwnsap = &((struct sockaddr_iso *)rt->rt_gateway)->siso_addr;
322: rt = rtalloc1(rt->rt_gateway, 0);
323: } else
324: rd_gwnsap = &((struct sockaddr_iso *)rt_key(rt))->siso_addr;
325: if (rt == 0 || (sdl = (struct sockaddr_dl *)rt->rt_gateway) == 0 ||
326: sdl->sdl_family != AF_LINK) {
327: /* maybe we should have a function that you
328: could put in the iso_ifaddr structure
329: which could translate iso_addrs into snpa's
330: where there is a known mapping for that address type */
331: esis_stat.es_badtype++;
332: return;
333: }
334: esis_stat.es_rdsent++;
335: IFDEBUG(D_ESISOUTPUT)
336: printf("esis_rdoutput: ifp x%x (%s%d), ht %d, m x%x, oidx x%x\n",
337: ifp, ifp->if_name, ifp->if_unit, esis_holding_time, inbound_m,
338: inbound_oidx);
339: printf("\tdestination: %s\n", clnp_iso_addrp(rd_dstnsap));
340: printf("\tredirected toward:%s\n", clnp_iso_addrp(rd_gwnsap));
341: ENDDEBUG
342:
343: if ((m0 = m = m_gethdr(M_DONTWAIT, MT_HEADER)) == NULL) {
344: esis_stat.es_nomem++;
345: return;
346: }
347: bzero(mtod(m, caddr_t), MHLEN);
348:
349: pdu = mtod(m, struct esis_fixed *);
350: cp = (caddr_t)(pdu + 1); /*pointer arith.; 1st byte after header */
351: len = sizeof(struct esis_fixed);
352:
353: /*
354: * Build fixed part of header
355: */
356: pdu->esis_proto_id = ISO9542_ESIS;
357: pdu->esis_vers = ESIS_VERSION;
358: pdu->esis_type = ESIS_RD;
359: HTOC(pdu->esis_ht_msb, pdu->esis_ht_lsb, esis_holding_time);
360:
361: /* Insert destination address */
362: (void) esis_insert_addr(&cp, &len, rd_dstnsap, m, 0);
363:
364: /* Insert the snpa of better next hop */
365: *cp++ = sdl->sdl_alen;
366: bcopy(LLADDR(sdl), cp, sdl->sdl_alen);
367: cp += sdl->sdl_alen;
368: len += (sdl->sdl_alen + 1);
369:
370: /*
371: * If the next hop is not the destination, then it ought to be
372: * an IS and it should be inserted next. Else, set the
373: * NETL to 0
374: */
375: /* PHASE2 use mask from ifp of outgoing interface */
376: if (!iso_addrmatch1(rd_dstnsap, rd_gwnsap)) {
377: /* this should not happen:
378: if ((nhop_sc->sc_flags & SNPA_IS) == 0) {
379: printf("esis_rdoutput: next hop is not dst and not an IS\n");
380: m_freem(m0);
381: return;
382: } */
383: (void) esis_insert_addr(&cp, &len, rd_gwnsap, m, 0);
384: } else {
385: *cp++ = 0; /* NETL */
386: len++;
387: }
388: m->m_len = len;
389:
390: /*
391: * PHASE2
392: * If redirect is to an IS, add an address mask. The mask to be
393: * used should be the mask present in the routing entry used to
394: * forward the original data packet.
395: */
396:
397: /*
398: * Copy Qos, priority, or security options present in original npdu
399: */
400: if (inbound_oidx) {
401: /* THIS CODE IS CURRENTLY (mostly) UNTESTED */
402: int optlen = 0;
403: if (inbound_oidx->cni_qos_formatp)
404: optlen += (inbound_oidx->cni_qos_len + 2);
405: if (inbound_oidx->cni_priorp) /* priority option is 1 byte long */
406: optlen += 3;
407: if (inbound_oidx->cni_securep)
408: optlen += (inbound_oidx->cni_secure_len + 2);
409: if (M_TRAILINGSPACE(m) < optlen) {
410: EXTEND_PACKET(m, m0, cp);
411: m->m_len = 0;
412: /* assumes MLEN > optlen */
413: }
414: /* assume MLEN-len > optlen */
415: /*
416: * When copying options, copy from ptr - 2 in order to grab
417: * the option code and length
418: */
419: if (inbound_oidx->cni_qos_formatp) {
420: bcopy(mtod(inbound_m, caddr_t) + inbound_oidx->cni_qos_formatp - 2,
421: cp, (unsigned)(inbound_oidx->cni_qos_len + 2));
422: cp += inbound_oidx->cni_qos_len + 2;
423: }
424: if (inbound_oidx->cni_priorp) {
425: bcopy(mtod(inbound_m, caddr_t) + inbound_oidx->cni_priorp - 2,
426: cp, 3);
427: cp += 3;
428: }
429: if (inbound_oidx->cni_securep) {
430: bcopy(mtod(inbound_m, caddr_t) + inbound_oidx->cni_securep - 2, cp,
431: (unsigned)(inbound_oidx->cni_secure_len + 2));
432: cp += inbound_oidx->cni_secure_len + 2;
433: }
434: m->m_len += optlen;
435: len += optlen;
436: }
437:
438: pdu->esis_hdr_len = m0->m_pkthdr.len = len;
439: iso_gen_csum(m0, ESIS_CKSUM_OFF, (int)pdu->esis_hdr_len);
440:
441: bzero((caddr_t)&siso, sizeof(siso));
442: siso.siso_family = AF_ISO;
443: siso.siso_data[0] = AFI_SNA;
444: siso.siso_nlen = 6 + 1; /* should be taken from snpa_hdr */
445: /* +1 is for AFI */
446: bcopy(inbound_shp->snh_shost, siso.siso_data + 1, 6);
447: (ifp->if_output)(ifp, m0, &siso, 0);
448: }
449:
450: /*
451: * FUNCTION: esis_insert_addr
452: *
453: * PURPOSE: Insert an iso_addr into a buffer
454: *
455: * RETURNS: true if buffer was big enough, else false
456: *
457: * SIDE EFFECTS: Increment buf & len according to size of iso_addr
458: *
459: * NOTES: Plus 1 here is for length byte
460: */
461: esis_insert_addr(buf, len, isoa, m, nsellen)
462: register caddr_t *buf; /* ptr to buffer to put address into */
463: int *len; /* ptr to length of buffer so far */
464: register struct iso_addr *isoa; /* ptr to address */
465: register struct mbuf *m; /* determine if there remains space */
466: int nsellen;
467: {
468: register int newlen, result = 0;
469:
470: isoa->isoa_len -= nsellen;
471: newlen = isoa->isoa_len + 1;
472: if (newlen <= M_TRAILINGSPACE(m)) {
473: bcopy((caddr_t)isoa, *buf, newlen);
474: *len += newlen;
475: *buf += newlen;
476: m->m_len += newlen;
477: result = 1;
478: }
479: isoa->isoa_len += nsellen;
480: return (result);
481: }
482:
483: #define ESIS_EXTRACT_ADDR(d, b) { d = (struct iso_addr *)(b); b += (1 + *b); \
484: if (b > buflim) {esis_stat.es_toosmall++; goto bad;}}
485: #define ESIS_NEXT_OPTION(b) { b += (2 + b[1]); \
486: if (b > buflim) {esis_stat.es_toosmall++; goto bad;}}
487: int ESHonly = 0;
488: /*
489:
490: /*
491: * FUNCTION: esis_eshinput
492: *
493: * PURPOSE: Process an incoming ESH pdu
494: *
495: * RETURNS: nothing
496: *
497: * SIDE EFFECTS:
498: *
499: * NOTES:
500: */
501: esis_eshinput(m, shp)
502: struct mbuf *m; /* esh pdu */
503: struct snpa_hdr *shp; /* subnetwork header */
504: {
505: struct esis_fixed *pdu = mtod(m, struct esis_fixed *);
506: u_short ht; /* holding time */
507: struct iso_addr *nsap;
508: int naddr;
509: u_char *buf = (u_char *)(pdu + 1);
510: u_char *buflim = pdu->esis_hdr_len + (u_char *)pdu;
511: int new_entry = 0;
512:
513: esis_stat.es_eshrcvd++;
514:
515: CTOH(pdu->esis_ht_msb, pdu->esis_ht_lsb, ht);
516:
517: naddr = *buf++;
518: if (buf >= buflim)
519: goto bad;
520: if (naddr == 1) {
521: ESIS_EXTRACT_ADDR(nsap, buf);
522: new_entry = snpac_add(shp->snh_ifp,
523: nsap, shp->snh_shost, SNPA_ES, ht, 0);
524: } else {
525: int nsellength = 0, nlen = 0;
526: {
527: /* See if we want to compress out multiple nsaps differing
528: only by nsel */
529: register struct ifaddr *ifa = shp->snh_ifp->if_addrlist;
530: for (; ifa; ifa = ifa->ifa_next)
531: if (ifa->ifa_addr->sa_family == AF_ISO) {
532: nsellength = ((struct iso_ifaddr *)ifa)->ia_addr.siso_tlen;
533: break;
534: }
535: }
536: IFDEBUG(D_ESISINPUT)
537: printf("esis_eshinput: esh: ht %d, naddr %d nsellength %d\n",
538: ht, naddr, nsellength);
539: ENDDEBUG
540: while (naddr-- > 0) {
541: struct iso_addr *nsap2; u_char *buf2;
542: ESIS_EXTRACT_ADDR(nsap, buf);
543: /* see if there is at least one more nsap in ESH differing
544: only by nsel */
545: if (nsellength != 0) for (buf2 = buf; buf2 < buflim;) {
546: ESIS_EXTRACT_ADDR(nsap2, buf2);
547: IFDEBUG(D_ESISINPUT)
548: printf("esis_eshinput: comparing %s ",
549: clnp_iso_addrp(nsap));
550: printf("and %s\n", clnp_iso_addrp(nsap2));
551: ENDDEBUG
552: if (Bcmp(nsap->isoa_genaddr, nsap2->isoa_genaddr,
553: nsap->isoa_len - nsellength) == 0) {
554: nlen = nsellength;
555: break;
556: }
557: }
558: new_entry |= snpac_add(shp->snh_ifp,
559: nsap, shp->snh_shost, SNPA_ES, ht, nlen);
560: nlen = 0;
561: }
562: }
563: IFDEBUG(D_ESISINPUT)
564: printf("esis_eshinput: nsap %s is %s\n",
565: clnp_iso_addrp(nsap), new_entry ? "new" : "old");
566: ENDDEBUG
567: if (new_entry && (iso_systype & SNPA_IS))
568: esis_shoutput(shp->snh_ifp, ESIS_ISH, esis_holding_time,
569: shp->snh_shost, 6, (struct iso_addr *)0);
570: bad:
571: return;
572: }
573:
574: /*
575: * FUNCTION: esis_ishinput
576: *
577: * PURPOSE: process an incoming ISH pdu
578: *
579: * RETURNS:
580: *
581: * SIDE EFFECTS:
582: *
583: * NOTES:
584: */
585: esis_ishinput(m, shp)
586: struct mbuf *m; /* esh pdu */
587: struct snpa_hdr *shp; /* subnetwork header */
588: {
589: struct esis_fixed *pdu = mtod(m, struct esis_fixed *);
590: u_short ht, newct; /* holding time */
591: struct iso_addr *nsap; /* Network Entity Title */
592: register u_char *buf = (u_char *) (pdu + 1);
593: register u_char *buflim = pdu->esis_hdr_len + (u_char *)pdu;
594: int new_entry;
595:
596: esis_stat.es_ishrcvd++;
597: CTOH(pdu->esis_ht_msb, pdu->esis_ht_lsb, ht);
598:
599: IFDEBUG(D_ESISINPUT)
600: printf("esis_ishinput: ish: ht %d\n", ht);
601: ENDDEBUG
602: if (ESHonly)
603: goto bad;
604:
605: ESIS_EXTRACT_ADDR(nsap, buf);
606:
607: while (buf < buflim) {
608: switch (*buf) {
609: case ESISOVAL_ESCT:
610: if (iso_systype & SNPA_IS)
611: break;
612: if (buf[1] != 2)
613: goto bad;
614: CTOH(buf[2], buf[3], newct);
615: if (esis_config_time != newct) {
616: untimeout(esis_config,0);
617: esis_config_time = newct;
618: esis_config();
619: }
620: break;
621:
622: default:
623: printf("Unknown ISH option: %x\n", *buf);
624: }
625: ESIS_NEXT_OPTION(buf);
626: }
627: new_entry = snpac_add(shp->snh_ifp, nsap, shp->snh_shost, SNPA_IS, ht, 0);
628: IFDEBUG(D_ESISINPUT)
629: printf("esis_ishinput: nsap %s is %s\n",
630: clnp_iso_addrp(nsap), new_entry ? "new" : "old");
631: ENDDEBUG
632:
633: if (new_entry)
634: esis_shoutput(shp->snh_ifp,
635: iso_systype & SNPA_ES ? ESIS_ESH : ESIS_ISH,
636: esis_holding_time, shp->snh_shost, 6, (struct iso_addr *)0);
637: bad:
638: return;
639: }
640:
641: /*
642: * FUNCTION: esis_rdinput
643: *
644: * PURPOSE: Process an incoming RD pdu
645: *
646: * RETURNS:
647: *
648: * SIDE EFFECTS:
649: *
650: * NOTES:
651: */
652: esis_rdinput(m0, shp)
653: struct mbuf *m0; /* esh pdu */
654: struct snpa_hdr *shp; /* subnetwork header */
655: {
656: struct esis_fixed *pdu = mtod(m0, struct esis_fixed *);
657: u_short ht; /* holding time */
658: struct iso_addr *da, *net = 0, *netmask = 0, *snpamask = 0;
659: register struct iso_addr *bsnpa;
660: register u_char *buf = (u_char *)(pdu + 1);
661: register u_char *buflim = pdu->esis_hdr_len + (u_char *)pdu;
662:
663: esis_stat.es_rdrcvd++;
664:
665: /* intermediate systems ignore redirects */
666: if (iso_systype & SNPA_IS)
667: return;
668: if (ESHonly)
669: return;
670:
671: CTOH(pdu->esis_ht_msb, pdu->esis_ht_lsb, ht);
672: if (buf >= buflim)
673: return;
674:
675: /* Extract DA */
676: ESIS_EXTRACT_ADDR(da, buf);
677:
678: /* Extract better snpa */
679: ESIS_EXTRACT_ADDR(bsnpa, buf);
680:
681: /* Extract NET if present */
682: if (buf < buflim) {
683: if (*buf == 0)
684: buf++; /* no NET present, skip NETL anyway */
685: else
686: ESIS_EXTRACT_ADDR(net, buf);
687: }
688:
689: /* process options */
690: while (buf < buflim) {
691: switch (*buf) {
692: case ESISOVAL_SNPAMASK:
693: if (snpamask) /* duplicate */
694: return;
695: snpamask = (struct iso_addr *)(buf + 1);
696: break;
697:
698: case ESISOVAL_NETMASK:
699: if (netmask) /* duplicate */
700: return;
701: netmask = (struct iso_addr *)(buf + 1);
702: break;
703:
704: default:
705: printf("Unknown option in ESIS RD (0x%x)\n", buf[-1]);
706: }
707: ESIS_NEXT_OPTION(buf);
708: }
709:
710: IFDEBUG(D_ESISINPUT)
711: printf("esis_rdinput: rd: ht %d, da %s\n", ht, clnp_iso_addrp(da));
712: if (net)
713: printf("\t: net %s\n", clnp_iso_addrp(net));
714: ENDDEBUG
715: /*
716: * If netl is zero, then redirect is to an ES. We need to add an entry
717: * to the snpa cache for (destination, better snpa).
718: * If netl is not zero, then the redirect is to an IS. In this
719: * case, add an snpa cache entry for (net, better snpa).
720: *
721: * If the redirect is to an IS, add a route entry towards that
722: * IS.
723: */
724: if (net == 0 || net->isoa_len == 0 || snpamask) {
725: /* redirect to an ES */
726: snpac_add(shp->snh_ifp, da,
727: bsnpa->isoa_genaddr, SNPA_ES, ht, 0);
728: } else {
729: snpac_add(shp->snh_ifp, net,
730: bsnpa->isoa_genaddr, SNPA_IS, ht, 0);
731: snpac_addrt(shp->snh_ifp, da, net, netmask);
732: }
733: bad: ; /* Needed by ESIS_NEXT_OPTION */
734: }
735:
736: /*
737: * FUNCTION: esis_config
738: *
739: * PURPOSE: Report configuration
740: *
741: * RETURNS:
742: *
743: * SIDE EFFECTS:
744: *
745: * NOTES: Called every esis_config_time seconds
746: */
747: esis_config()
748: {
749: register struct ifnet *ifp;
750:
751: timeout(esis_config, (caddr_t)0, hz * esis_config_time);
752:
753: /*
754: * Report configuration for each interface that
755: * - is UP
756: * - has BROADCAST capability
757: * - has an ISO address
758: */
759: /* Todo: a better way would be to construct the esh or ish
760: * once and copy it out for all devices, possibly calling
761: * a method in the iso_ifaddr structure to encapsulate and
762: * transmit it. This could work to advantage for non-broadcast media
763: */
764:
765: for (ifp = ifnet; ifp; ifp = ifp->if_next) {
766: if ((ifp->if_flags & IFF_UP) &&
767: (ifp->if_flags & IFF_BROADCAST)) {
768: /* search for an ISO address family */
769: struct ifaddr *ia;
770:
771: for (ia = ifp->if_addrlist; ia; ia = ia->ifa_next) {
772: if (ia->ifa_addr->sa_family == AF_ISO) {
773: esis_shoutput(ifp,
774: iso_systype & SNPA_ES ? ESIS_ESH : ESIS_ISH,
775: esis_holding_time,
776: (caddr_t)(iso_systype & SNPA_ES ? all_is_snpa :
777: all_es_snpa), 6, (struct iso_addr *)0);
778: break;
779: }
780: }
781: }
782: }
783: }
784:
785: /*
786: * FUNCTION: esis_shoutput
787: *
788: * PURPOSE: Transmit an esh or ish pdu
789: *
790: * RETURNS: nothing
791: *
792: * SIDE EFFECTS:
793: *
794: * NOTES:
795: */
796: esis_shoutput(ifp, type, ht, sn_addr, sn_len, isoa)
797: struct ifnet *ifp;
798: int type;
799: short ht;
800: caddr_t sn_addr;
801: int sn_len;
802: struct iso_addr *isoa;
803: {
804: struct mbuf *m, *m0;
805: caddr_t cp, naddrp;
806: int naddr = 0;
807: struct esis_fixed *pdu;
808: struct iso_ifaddr *ia;
809: int len;
810: struct sockaddr_iso siso;
811:
812: if (type == ESIS_ESH)
813: esis_stat.es_eshsent++;
814: else if (type == ESIS_ISH)
815: esis_stat.es_ishsent++;
816: else {
817: printf("esis_shoutput: bad pdu type\n");
818: return;
819: }
820:
821: IFDEBUG(D_ESISOUTPUT)
822: int i;
823: printf("esis_shoutput: ifp x%x (%s%d), %s, ht %d, to: [%d] ",
824: ifp, ifp->if_name, ifp->if_unit, type == ESIS_ESH ? "esh" : "ish",
825: ht, sn_len);
826: for (i=0; i<sn_len; i++)
827: printf("%x%c", *(sn_addr+i), i < (sn_len-1) ? ':' : ' ');
828: printf("\n");
829: ENDDEBUG
830:
831: if ((m0 = m = m_gethdr(M_DONTWAIT, MT_HEADER)) == NULL) {
832: esis_stat.es_nomem++;
833: return;
834: }
835: bzero(mtod(m, caddr_t), MHLEN);
836:
837: pdu = mtod(m, struct esis_fixed *);
838: naddrp = cp = (caddr_t)(pdu + 1);
839: len = sizeof(struct esis_fixed);
840:
841: /*
842: * Build fixed part of header
843: */
844: pdu->esis_proto_id = ISO9542_ESIS;
845: pdu->esis_vers = ESIS_VERSION;
846: pdu->esis_type = type;
847: HTOC(pdu->esis_ht_msb, pdu->esis_ht_lsb, ht);
848:
849: if (type == ESIS_ESH) {
850: cp++;
851: len++;
852: }
853:
854: m->m_len = len;
855: if (isoa) {
856: /*
857: * Here we are responding to a clnp packet sent to an NSAP
858: * that is ours which was sent to the MAC addr all_es's.
859: * It is possible that we did not specifically advertise this
860: * NSAP, even though it is ours, so we will respond
861: * directly to the sender that we are here. If we do have
862: * multiple NSEL's we'll tack them on so he can compress them out.
863: */
864: (void) esis_insert_addr(&cp, &len, isoa, m, 0);
865: naddr = 1;
866: }
867: for (ia = iso_ifaddr; ia; ia = ia->ia_next) {
868: int nsellen = (type == ESIS_ISH ? ia->ia_addr.siso_tlen : 0);
869: int n = ia->ia_addr.siso_nlen;
870: register struct iso_ifaddr *ia2;
871:
872: if (type == ESIS_ISH && naddr > 0)
873: break;
874: for (ia2 = iso_ifaddr; ia2 != ia; ia2 = ia2->ia_next)
875: if (Bcmp(ia->ia_addr.siso_data, ia2->ia_addr.siso_data, n) == 0)
876: break;
877: if (ia2 != ia)
878: continue; /* Means we have previously copied this nsap */
879: if (isoa && Bcmp(ia->ia_addr.siso_data, isoa->isoa_genaddr, n) == 0) {
880: isoa = 0;
881: continue; /* Ditto */
882: }
883: IFDEBUG(D_ESISOUTPUT)
884: printf("esis_shoutput: adding NSAP %s\n",
885: clnp_iso_addrp(&ia->ia_addr.siso_addr));
886: ENDDEBUG
887: if (!esis_insert_addr(&cp, &len,
888: &ia->ia_addr.siso_addr, m, nsellen)) {
889: EXTEND_PACKET(m, m0, cp);
890: (void) esis_insert_addr(&cp, &len, &ia->ia_addr.siso_addr, m,
891: nsellen);
892: }
893: naddr++;
894: }
895:
896: if (type == ESIS_ESH)
897: *naddrp = naddr;
898: else {
899: /* add suggested es config timer option to ISH */
900: if (M_TRAILINGSPACE(m) < 4) {
901: printf("esis_shoutput: extending packet\n");
902: EXTEND_PACKET(m, m0, cp);
903: }
904: *cp++ = ESISOVAL_ESCT;
905: *cp++ = 2;
906: HTOC(*cp, *(cp+1), esis_esconfig_time);
907: len += 4;
908: m->m_len += 4;
909: IFDEBUG(D_ESISOUTPUT)
910: printf("m0 0x%x, m 0x%x, data 0x%x, len %d, cp 0x%x\n",
911: m0, m, m->m_data, m->m_len, cp);
912: ENDDEBUG
913: }
914:
915: m0->m_pkthdr.len = len;
916: pdu->esis_hdr_len = len;
917: iso_gen_csum(m0, ESIS_CKSUM_OFF, (int)pdu->esis_hdr_len);
918:
919: bzero((caddr_t)&siso, sizeof(siso));
920: siso.siso_family = AF_ISO;
921: siso.siso_data[0] = AFI_SNA;
922: siso.siso_nlen = sn_len + 1;
923: bcopy(sn_addr, siso.siso_data + 1, (unsigned)sn_len);
924: (ifp->if_output)(ifp, m0, &siso, 0);
925: }
926:
927: /*
928: * FUNCTION: isis_input
929: *
930: * PURPOSE: Process an incoming isis packet
931: *
932: * RETURNS: nothing
933: *
934: * SIDE EFFECTS:
935: *
936: * NOTES:
937: */
938: isis_input(m0, shp)
939: struct mbuf *m0; /* ptr to first mbuf of pkt */
940: struct snpa_hdr *shp; /* subnetwork header */
941: {
942: register int type;
943: register struct rawcb *rp, *first_rp = 0;
944: struct ifnet *ifp = shp->snh_ifp;
945: char workbuf[16];
946: struct mbuf *mm;
947:
948: IFDEBUG(D_ISISINPUT)
949: int i;
950:
951: printf("isis_input: pkt on ifp x%x (%s%d): from:", ifp,
952: ifp->if_name, ifp->if_unit);
953: for (i=0; i<6; i++)
954: printf("%x%c", shp->snh_shost[i]&0xff, (i<5) ? ':' : ' ');
955: printf(" to:");
956: for (i=0; i<6; i++)
957: printf("%x%c", shp->snh_dhost[i]&0xff, (i<5) ? ':' : ' ');
958: printf("\n");
959: ENDDEBUG
960: esis_dl.sdl_alen = ifp->if_addrlen;
961: esis_dl.sdl_index = ifp->if_index;
962: bcopy(shp->snh_shost, (caddr_t)esis_dl.sdl_data, esis_dl.sdl_alen);
963: for (rp = esis_pcb.rcb_next; rp != &esis_pcb; rp = rp->rcb_next) {
964: if (first_rp == 0) {
965: first_rp = rp;
966: continue;
967: }
968: if (mm = m_copy(m0, 0, M_COPYALL)) { /*can't block at interrupt level */
969: if (sbappendaddr(&rp->rcb_socket->so_rcv,
970: &esis_dl, mm, (struct mbuf *)0) != 0)
971: sorwakeup(rp->rcb_socket);
972: else {
973: IFDEBUG(D_ISISINPUT)
974: printf("Error in sbappenaddr, mm = 0x%x\n", mm);
975: ENDDEBUG
976: m_freem(mm);
977: }
978: }
979: }
980: if (first_rp && sbappendaddr(&first_rp->rcb_socket->so_rcv,
981: &esis_dl, m0, (struct mbuf *)0) != 0) {
982: sorwakeup(first_rp->rcb_socket);
983: return;
984: }
985: m_freem(m0);
986: }
987:
988: isis_output(sdl, m)
989: register struct sockaddr_dl *sdl;
990: struct mbuf *m;
991: {
992: register struct ifnet *ifp;
993: struct ifaddr *ifa, *ifa_ifwithnet();
994: struct sockaddr_iso siso;
995: int error = 0;
996: unsigned sn_len;
997:
998: ifa = ifa_ifwithnet(sdl); /* extract ifp from sockaddr_dl */
999: if (ifa == 0) {
1000: IFDEBUG(D_ISISOUTPUT)
1001: printf("isis_output: interface not found\n");
1002: ENDDEBUG
1003: error = EINVAL;
1004: goto release;
1005: }
1006: ifp = ifa->ifa_ifp;
1007: sn_len = sdl->sdl_alen;
1008: IFDEBUG(D_ISISOUTPUT)
1009: u_char *cp = (u_char *)LLADDR(sdl), *cplim = cp + sn_len;
1010: printf("isis_output: ifp 0x%x (%s%d), to: ",
1011: ifp, ifp->if_name, ifp->if_unit);
1012: while (cp < cplim) {
1013: printf("%x", *cp++);
1014: printf("%c", (cp < cplim) ? ':' : ' ');
1015: }
1016: printf("\n");
1017: ENDDEBUG
1018: bzero((caddr_t)&siso, sizeof(siso));
1019: siso.siso_family = AF_ISO; /* This convention may be useful for X.25 */
1020: siso.siso_data[0] = AFI_SNA;
1021: siso.siso_nlen = sn_len + 1;
1022: bcopy(LLADDR(sdl), siso.siso_data + 1, sn_len);
1023: error = (ifp->if_output)(ifp, m, (struct sockaddr *)&siso, 0);
1024: if (error) {
1025: IFDEBUG(D_ISISOUTPUT)
1026: printf("isis_output: error from ether_output is %d\n", error);
1027: ENDDEBUG
1028: }
1029: return (error);
1030:
1031: release:
1032: if (m != NULL)
1033: m_freem(m);
1034: return(error);
1035: }
1036:
1037:
1038: /*
1039: * FUNCTION: esis_ctlinput
1040: *
1041: * PURPOSE: Handle the PRC_IFDOWN transition
1042: *
1043: * RETURNS: nothing
1044: *
1045: * SIDE EFFECTS:
1046: *
1047: * NOTES: Calls snpac_flush for interface specified.
1048: * The loop through iso_ifaddr is stupid because
1049: * back in if_down, we knew the ifp...
1050: */
1051: esis_ctlinput(req, siso)
1052: int req; /* request: we handle only PRC_IFDOWN */
1053: struct sockaddr_iso *siso; /* address of ifp */
1054: {
1055: register struct iso_ifaddr *ia; /* scan through interface addresses */
1056:
1057: if (req == PRC_IFDOWN)
1058: for (ia = iso_ifaddr; ia; ia = ia->ia_next) {
1059: if (iso_addrmatch(IA_SIS(ia), siso))
1060: snpac_flushifp(ia->ia_ifp);
1061: }
1062: }
1063:
1064: #endif ISO
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.