/sys/src/9/ip/ipv6.h % cat >/sys/lib/dist/changes/1176838212.0.txt << EOF • Code cleanup • Fix up ICMP6 EOF [geoff] --rw-rw-r-- M 64 presotto sys 4087 Apr 17 17:06 sys/src/9/ip/ipv6.h /n/sourcesdump/2007/0417/plan9/sys/src/9/ip/ipv6.h:1,4 - /n/sourcesdump/2007/0418/plan9/sys/src/9/ip/ipv6.h:1,6 - #define MIN(a, b) ((a) <= (b) ? (a) : (b)) + #ifndef MIN + #define MIN(a, b) ((a) <= (b)? (a): (b)) + #endif /* rfc 3513 defines the address prefices */ #define isv6mcast(addr) ((addr)[0] == 0xff) /n/sourcesdump/2007/0417/plan9/sys/src/9/ip/ipv6.h:6,52 - /n/sourcesdump/2007/0418/plan9/sys/src/9/ip/ipv6.h:8,20 #define issitelocal(addr) ((addr)[0] == 0xfe && ((addr)[1] & 0xc0) == 0xc0) #define isv6global(addr) (((addr)[0] & 0xe0) == 0x20) - #define optexsts(np) (nhgets((np)->ploadlen) > 24) - #define issmcast(addr) (memcmp((addr), v6solicitednode, 13) == 0) + #define optexsts(np) (nhgets((np)->ploadlen) > 24) + #define issmcast(addr) (memcmp((addr), v6solicitednode, 13) == 0) /* from RFC 2460 */ - typedef struct Ip6hdr Ip6hdr; - typedef struct Opthdr Opthdr; - typedef struct Routinghdr Routinghdr; - typedef struct Fraghdr6 Fraghdr6; - - struct Ip6hdr { - uchar vcf[4]; // version:4, traffic class:8, flow label:20 - uchar ploadlen[2]; // payload length: packet length - 40 - uchar proto; // next header type - uchar ttl; // hop limit - uchar src[IPaddrlen]; - uchar dst[IPaddrlen]; - }; - - struct Opthdr { - uchar nexthdr; - uchar len; - }; - - struct Routinghdr { - uchar nexthdr; - uchar len; - uchar rtetype; - uchar segrem; - }; - - struct Fraghdr6 { - uchar nexthdr; - uchar res; - uchar offsetRM[2]; // Offset, Res, M flag - uchar id[4]; - }; - - - enum { /* Header Types */ - HBH = 0, //? + enum { /* Header Types */ + HBH = 0, /* hop-by-hop multicast routing protocol */ ICMP = 1, IGMP = 2, GGP = 3, /n/sourcesdump/2007/0417/plan9/sys/src/9/ip/ipv6.h:71,159 - /n/sourcesdump/2007/0418/plan9/sys/src/9/ip/ipv6.h:39,146 Maxhdrtype = 256, }; - enum { - // multicast flgs and scop + /* multicast flags and scopes */ - well_known_flg = 0, - transient_flg = 1, + Well_known_flg = 0, + Transient_flg = 1, - node_local_scop = 1, - link_local_scop = 2, - site_local_scop = 5, - org_local_scop = 8, - global_scop = 14, + Node_local_scop = 1, + Link_local_scop = 2, + Site_local_scop = 5, + Org_local_scop = 8, + Global_scop = 14, - // various prefix lengths + /* various prefix lengths */ + SOLN_PREF_LEN = 13, - SOLN_PREF_LEN = 13, + /* icmpv6 unreach codes */ + icmp6_no_route = 0, + icmp6_ad_prohib = 1, + icmp6_unassigned = 2, + icmp6_adr_unreach = 3, + icmp6_port_unreach = 4, + icmp6_unkn_code = 5, - // icmpv6 unreach codes - icmp6_no_route = 0, - icmp6_ad_prohib = 1, - icmp6_unassigned = 2, - icmp6_adr_unreach = 3, - icmp6_port_unreach = 4, - icmp6_unkn_code = 5, + /* various flags & constants */ + v6MINTU = 1280, + HOP_LIMIT = 255, + ETHERHDR_LEN = 14, + IPV6HDR_LEN = 40, + IPV4HDR_LEN = 20, - // various flags & constants + /* option types */ - v6MINTU = 1280, - HOP_LIMIT = 255, - ETHERHDR_LEN = 14, - IPV6HDR_LEN = 40, - IPV4HDR_LEN = 20, + SRC_LLADDR = 1, + TARGET_LLADDR = 2, + PREFIX_INFO = 3, + REDIR_HEADER = 4, + MTU_OPTION = 5, - // option types + SRC_UNSPEC = 0, + SRC_UNI = 1, + TARG_UNI = 2, + TARG_MULTI = 3, - SRC_LLADDRESS = 1, - TARGET_LLADDRESS = 2, - PREFIX_INFO = 3, - REDIR_HEADER = 4, - MTU_OPTION = 5, + t_unitent = 1, + t_uniproxy = 2, + t_unirany = 3, - SRC_UNSPEC = 0, - SRC_UNI = 1, - TARG_UNI = 2, - TARG_MULTI = 3, + /* Router constants (all times in milliseconds) */ + MAX_INIT_RTR_ADVERT_INTVL = 16000, + MAX_INIT_RTR_ADVERTS = 3, + MAX_FINAL_RTR_ADVERTS = 3, + MIN_DELAY_BETWEEN_RAS = 3000, + MAX_RA_DELAY_TIME = 500, - t_unitent = 1, - t_uniproxy = 2, - t_unirany = 3, + /* Host constants */ + MAX_RTR_SOLICIT_DELAY = 1000, + RTR_SOLICIT_INTVL = 4000, + MAX_RTR_SOLICITS = 3, - // Router constants (all times in milliseconds) + /* Node constants */ + MAX_MULTICAST_SOLICIT = 3, + MAX_UNICAST_SOLICIT = 3, + MAX_ANYCAST_DELAY_TIME = 1000, + MAX_NEIGHBOR_ADVERT = 3, + REACHABLE_TIME = 30000, + RETRANS_TIMER = 1000, + DELAY_FIRST_PROBE_TIME = 5000, + }; - MAX_INITIAL_RTR_ADVERT_INTERVAL = 16000, - MAX_INITIAL_RTR_ADVERTISEMENTS = 3, - MAX_FINAL_RTR_ADVERTISEMENTS = 3, - MIN_DELAY_BETWEEN_RAS = 3000, - MAX_RA_DELAY_TIME = 500, + typedef struct Ip6hdr Ip6hdr; + typedef struct Opthdr Opthdr; + typedef struct Routinghdr Routinghdr; + typedef struct Fraghdr6 Fraghdr6; - // Host constants + struct Ip6hdr { + uchar vcf[4]; /* version:4, traffic class:8, flow label:20 */ + uchar ploadlen[2]; /* payload length: packet length - 40 */ + uchar proto; /* next header type */ + uchar ttl; /* hop limit */ + uchar src[IPaddrlen]; + uchar dst[IPaddrlen]; + }; - MAX_RTR_SOLICITATION_DELAY = 1000, - RTR_SOLICITATION_INTERVAL = 4000, - MAX_RTR_SOLICITATIONS = 3, + struct Opthdr { + uchar nexthdr; + uchar len; + }; - // Node constants + struct Routinghdr { + uchar nexthdr; + uchar len; + uchar rtetype; + uchar segrem; + }; - MAX_MULTICAST_SOLICIT = 3, - MAX_UNICAST_SOLICIT = 3, - MAX_ANYCAST_DELAY_TIME = 1000, - MAX_NEIGHBOR_ADVERTISEMENT = 3, - REACHABLE_TIME = 30000, - RETRANS_TIMER = 1000, - DELAY_FIRST_PROBE_TIME = 5000, - + struct Fraghdr6 { + uchar nexthdr; + uchar res; + uchar offsetRM[2]; /* Offset, Res, M flag */ + uchar id[4]; }; - extern void ipv62smcast(uchar *, uchar *); - extern void icmpns(Fs *f, uchar* src, int suni, uchar* targ, int tuni, uchar* mac); - extern void icmpna(Fs *f, uchar* src, uchar* dst, uchar* targ, uchar* mac, uchar flags); - extern void icmpttlexceeded6(Fs *f, Ipifc *ifc, Block *bp); - extern void icmppkttoobig6(Fs *f, Ipifc *ifc, Block *bp); - extern void icmphostunr(Fs *f, Ipifc *ifc, Block *bp, int code, int free); - extern uchar v6allnodesN[IPaddrlen]; extern uchar v6allnodesL[IPaddrlen]; extern uchar v6allroutersN[IPaddrlen]; /n/sourcesdump/2007/0417/plan9/sys/src/9/ip/ipv6.h:183,185 - /n/sourcesdump/2007/0418/plan9/sys/src/9/ip/ipv6.h:170,179 extern int v6aLpreflen; extern int ReTransTimer; + + void ipv62smcast(uchar *, uchar *); + void icmpns(Fs *f, uchar* src, int suni, uchar* targ, int tuni, uchar* mac); + void icmpna(Fs *f, uchar* src, uchar* dst, uchar* targ, uchar* mac, uchar flags); + void icmpttlexceeded6(Fs *f, Ipifc *ifc, Block *bp); + void icmppkttoobig6(Fs *f, Ipifc *ifc, Block *bp); + void icmphostunr(Fs *f, Ipifc *ifc, Block *bp, int code, int free); [geoff] --rw-rw-r-- M 64 presotto sys 17914 Apr 17 17:07 sys/src/9/ip/icmp6.c /n/sourcesdump/2007/0417/plan9/sys/src/9/ip/icmp6.c:1,3 - /n/sourcesdump/2007/0418/plan9/sys/src/9/ip/icmp6.c:1,6 + /* + * Internet Control Message Protocol for IPv6 + */ #include "u.h" #include "../port/lib.h" #include "mem.h" /n/sourcesdump/2007/0417/plan9/sys/src/9/ip/icmp6.c:7,47 - /n/sourcesdump/2007/0418/plan9/sys/src/9/ip/icmp6.c:10,45 #include "ip.h" #include "ipv6.h" - typedef struct ICMPpkt ICMPpkt; - typedef struct IPICMP IPICMP; - typedef struct Ndpkt Ndpkt; - typedef struct NdiscC NdiscC; + enum + { + InMsgs6, + InErrors6, + OutMsgs6, + CsumErrs6, + LenErrs6, + HlenErrs6, + HoplimErrs6, + IcmpCodeErrs6, + TargetErrs6, + OptlenErrs6, + AddrmxpErrs6, + RouterAddrErrs6, - struct ICMPpkt { - uchar type; - uchar code; - uchar cksum[2]; - uchar icmpid[2]; - uchar seq[2]; + Nstats6, }; - struct IPICMP { - Ip6hdr; - ICMPpkt; + enum { + ICMP_USEAD6 = 40, }; - struct NdiscC - { - IPICMP; - uchar target[IPaddrlen]; + enum { + Oflag = 1<<5, + Sflag = 1<<6, + Rflag = 1<<7, }; - struct Ndpkt - { - NdiscC; - uchar otype; - uchar olen; // length in units of 8 octets(incl type, code), - // 1 for IEEE 802 addresses - uchar lnaddr[6]; // link-layer address - }; - - enum { - // ICMPv6 types + enum { + /* ICMPv6 types */ EchoReply = 0, UnreachableV6 = 1, PacketTooBigV6 = 2, /n/sourcesdump/2007/0417/plan9/sys/src/9/ip/icmp6.c:69,74 - /n/sourcesdump/2007/0418/plan9/sys/src/9/ip/icmp6.c:67,120 Maxtype6 = 137, }; + typedef struct ICMPpkt ICMPpkt; + typedef struct IPICMP IPICMP; + typedef struct Ndpkt Ndpkt; + typedef struct NdiscC NdiscC; + + struct ICMPpkt { + uchar type; + uchar code; + uchar cksum[2]; + uchar icmpid[2]; + uchar seq[2]; + }; + + struct IPICMP { + Ip6hdr; + ICMPpkt; + }; + + struct NdiscC + { + IPICMP; + uchar target[IPaddrlen]; + }; + + struct Ndpkt + { + NdiscC; + uchar otype; + uchar olen; /* length in units of 8 octets(incl type, code), + * 1 for IEEE 802 addresses */ + uchar lnaddr[6]; /* link-layer address */ + }; + + typedef struct Icmppriv6 + { + ulong stats[Nstats6]; + + /* message counts */ + ulong in[Maxtype6+1]; + ulong out[Maxtype6+1]; + } Icmppriv6; + + typedef struct Icmpcb6 + { + QLock; + uchar headers; + } Icmpcb6; + char *icmpnames6[Maxtype6+1] = { [EchoReply] "EchoReply", /n/sourcesdump/2007/0417/plan9/sys/src/9/ip/icmp6.c:95,118 - /n/sourcesdump/2007/0418/plan9/sys/src/9/ip/icmp6.c:141,146 [RedirectV6] "RedirectV6", }; - enum - { - InMsgs6, - InErrors6, - OutMsgs6, - CsumErrs6, - LenErrs6, - HlenErrs6, - HoplimErrs6, - IcmpCodeErrs6, - TargetErrs6, - OptlenErrs6, - AddrmxpErrs6, - RouterAddrErrs6, - - Nstats6, - }; - static char *statnames6[Nstats6] = { [InMsgs6] "InMsgs", /n/sourcesdump/2007/0417/plan9/sys/src/9/ip/icmp6.c:129,149 - /n/sourcesdump/2007/0418/plan9/sys/src/9/ip/icmp6.c:157,162 [RouterAddrErrs6] "RouterAddrErrs", }; - typedef struct Icmppriv6 - { - ulong stats[Nstats6]; - - /* message counts */ - ulong in[Maxtype6+1]; - ulong out[Maxtype6+1]; - } Icmppriv6; - - typedef struct Icmpcb6 - { - QLock; - uchar headers; - } Icmpcb6; - static char *unreachcode[] = { [icmp6_no_route] "no route to destination", /n/sourcesdump/2007/0417/plan9/sys/src/9/ip/icmp6.c:154,177 - /n/sourcesdump/2007/0418/plan9/sys/src/9/ip/icmp6.c:167,172 [icmp6_unkn_code] "icmp unreachable: unknown code", }; - enum { - ICMP_USEAD6 = 40, - }; - - enum { - Oflag = 1<<5, - Sflag = 1<<6, - Rflag = 1<<7, - }; - - enum { - slladd = 1, - tlladd = 2, - prfinfo = 3, - redhdr = 4, - mtuopt = 5, - }; - static void icmpkick6(void *x, Block *bp); static void /n/sourcesdump/2007/0417/plan9/sys/src/9/ip/icmp6.c:186,195 - /n/sourcesdump/2007/0418/plan9/sys/src/9/ip/icmp6.c:181,190 { IPICMP *p = (IPICMP *)(bp->rp); - hnputl(p->vcf, 0); // borrow IP header as pseudoheader + hnputl(p->vcf, 0); /* borrow IP header as pseudoheader */ hnputs(p->ploadlen, blocklen(bp)-IPV6HDR_LEN); p->proto = 0; - p->ttl = ICMPv6; // ttl gets set later + p->ttl = ICMPv6; /* ttl gets set later */ hnputs(p->cksum, 0); hnputs(p->cksum, ptclcsum(bp, 0, blocklen(bp))); p->proto = ICMPv6; /n/sourcesdump/2007/0417/plan9/sys/src/9/ip/icmp6.c:198,204 - /n/sourcesdump/2007/0418/plan9/sys/src/9/ip/icmp6.c:193,200 static Block * newIPICMP(int packetlen) { - Block *nbp; + Block *nbp; + nbp = allocb(packetlen); nbp->wp += packetlen; memset(nbp->rp, 0, packetlen); /n/sourcesdump/2007/0417/plan9/sys/src/9/ip/icmp6.c:208,224 - /n/sourcesdump/2007/0418/plan9/sys/src/9/ip/icmp6.c:204,219 void icmpadvise6(Proto *icmp, Block *bp, char *msg) { - Conv **c, *s; - IPICMP *p; - ushort recid; + ushort recid; + Conv **c, *s; + IPICMP *p; - p = (IPICMP *) bp->rp; + p = (IPICMP *)bp->rp; recid = nhgets(p->icmpid); for(c = icmp->conv; *c; c++) { s = *c; - if(s->lport == recid) - if(ipcmp(s->raddr, p->dst) == 0){ + if(s->lport == recid && ipcmp(s->raddr, p->dst) == 0){ qhangup(s->rq, msg); qhangup(s->wq, msg); break; /n/sourcesdump/2007/0417/plan9/sys/src/9/ip/icmp6.c:230,238 - /n/sourcesdump/2007/0418/plan9/sys/src/9/ip/icmp6.c:225,233 static void icmpkick6(void *x, Block *bp) { + uchar laddr[IPaddrlen], raddr[IPaddrlen]; Conv *c = x; IPICMP *p; - uchar laddr[IPaddrlen], raddr[IPaddrlen]; Icmppriv6 *ipriv = c->p->priv; Icmpcb6 *icb = (Icmpcb6*)c->ptcl; /n/sourcesdump/2007/0417/plan9/sys/src/9/ip/icmp6.c:268,274 - /n/sourcesdump/2007/0418/plan9/sys/src/9/ip/icmp6.c:263,269 set_cksum(bp); p->vcf[0] = 0x06 << 4; - if(p->type <= Maxtype6) + if(p->type <= Maxtype6) ipriv->out[p->type]++; ipoput6(c->p->f, bp, 0, c->ttl, c->tos, nil); } /n/sourcesdump/2007/0417/plan9/sys/src/9/ip/icmp6.c:279,290 - /n/sourcesdump/2007/0418/plan9/sys/src/9/ip/icmp6.c:274,282 Icmpcb6 *icb; icb = (Icmpcb6*) c->ptcl; - - if(argc==1) { - if(strcmp(argv[0], "headers")==0) { - icb->headers = 6; - return nil; - } + if(argc==1 && strcmp(argv[0], "headers")==0) { + icb->headers = 6; + return nil; } return "unknown control request"; } /n/sourcesdump/2007/0417/plan9/sys/src/9/ip/icmp6.c:292,307 - /n/sourcesdump/2007/0418/plan9/sys/src/9/ip/icmp6.c:284,298 static void goticmpkt6(Proto *icmp, Block *bp, int muxkey) { + ushort recid; + uchar *addr; Conv **c, *s; IPICMP *p = (IPICMP *)bp->rp; - ushort recid; - uchar *addr; if(muxkey == 0) { recid = nhgets(p->icmpid); addr = p->src; - } - else { + } else { recid = muxkey; addr = p->dst; } /n/sourcesdump/2007/0417/plan9/sys/src/9/ip/icmp6.c:322,329 - /n/sourcesdump/2007/0418/plan9/sys/src/9/ip/icmp6.c:313,320 static Block * mkechoreply6(Block *bp) { + uchar addr[IPaddrlen]; IPICMP *p = (IPICMP *)(bp->rp); - uchar addr[IPaddrlen]; ipmove(addr, p->src); ipmove(p->src, p->dst); /n/sourcesdump/2007/0417/plan9/sys/src/9/ip/icmp6.c:335,361 - /n/sourcesdump/2007/0418/plan9/sys/src/9/ip/icmp6.c:326,349 /* * sends out an ICMPv6 neighbor solicitation - * suni == SRC_UNSPEC or SRC_UNI, + * suni == SRC_UNSPEC or SRC_UNI, * tuni == TARG_MULTI => multicast for address resolution, * and tuni == TARG_UNI => neighbor reachability. */ - extern void icmpns(Fs *f, uchar* src, int suni, uchar* targ, int tuni, uchar* mac) { - Block *nbp; + Block *nbp; Ndpkt *np; Proto *icmp = f->t2p[ICMPv6]; Icmppriv6 *ipriv = icmp->priv; - nbp = newIPICMP(sizeof(Ndpkt)); np = (Ndpkt*) nbp->rp; - - if(suni == SRC_UNSPEC) + if(suni == SRC_UNSPEC) memmove(np->src, v6Unspecified, IPaddrlen); - else + else memmove(np->src, src, IPaddrlen); if(tuni == TARG_UNI) /n/sourcesdump/2007/0417/plan9/sys/src/9/ip/icmp6.c:367,383 - /n/sourcesdump/2007/0418/plan9/sys/src/9/ip/icmp6.c:355,368 np->code = 0; memmove(np->target, targ, IPaddrlen); if(suni != SRC_UNSPEC) { - np->otype = SRC_LLADDRESS; - np->olen = 1; /* 1+1+6 = 8 = 1 8-octet */ + np->otype = SRC_LLADDR; + np->olen = 1; /* 1+1+6 = 8 = 1 8-octet */ memmove(np->lnaddr, mac, sizeof(np->lnaddr)); - } - else { - int r = sizeof(Ndpkt)-sizeof(NdiscC); - nbp->wp -= r; - } + } else + nbp->wp -= sizeof(Ndpkt) - sizeof(NdiscC); set_cksum(nbp); - np = (Ndpkt*) nbp->rp; + np = (Ndpkt*)nbp->rp; np->ttl = HOP_LIMIT; np->vcf[0] = 0x06 << 4; ipriv->out[NbrSolicit]++; /n/sourcesdump/2007/0417/plan9/sys/src/9/ip/icmp6.c:391,403 - /n/sourcesdump/2007/0418/plan9/sys/src/9/ip/icmp6.c:376,388 extern void icmpna(Fs *f, uchar* src, uchar* dst, uchar* targ, uchar* mac, uchar flags) { - Block *nbp; + Block *nbp; Ndpkt *np; Proto *icmp = f->t2p[ICMPv6]; Icmppriv6 *ipriv = icmp->priv; nbp = newIPICMP(sizeof(Ndpkt)); - np = (Ndpkt*) nbp->rp; + np = (Ndpkt*)nbp->rp; memmove(np->src, src, IPaddrlen); memmove(np->dst, dst, IPaddrlen); /n/sourcesdump/2007/0417/plan9/sys/src/9/ip/icmp6.c:407,414 - /n/sourcesdump/2007/0418/plan9/sys/src/9/ip/icmp6.c:392,399 np->icmpid[0] = flags; memmove(np->target, targ, IPaddrlen); - np->otype = TARGET_LLADDRESS; - np->olen = 1; + np->otype = TARGET_LLADDR; + np->olen = 1; memmove(np->lnaddr, mac, sizeof(np->lnaddr)); set_cksum(nbp); /n/sourcesdump/2007/0417/plan9/sys/src/9/ip/icmp6.c:423,452 - /n/sourcesdump/2007/0418/plan9/sys/src/9/ip/icmp6.c:408,438 extern void icmphostunr(Fs *f, Ipifc *ifc, Block *bp, int code, int free) { - Block *nbp; - IPICMP *np; - Ip6hdr *p; int osz = BLEN(bp); int sz = MIN(sizeof(IPICMP) + osz, v6MINTU); - Proto *icmp = f->t2p[ICMPv6]; + Block *nbp; + IPICMP *np; + Ip6hdr *p; + Proto *icmp = f->t2p[ICMPv6]; Icmppriv6 *ipriv = icmp->priv; - p = (Ip6hdr *) bp->rp; + p = (Ip6hdr *)bp->rp; - if(isv6mcast(p->src)) + if(isv6mcast(p->src)) goto clean; nbp = newIPICMP(sz); - np = (IPICMP *) nbp->rp; + np = (IPICMP *)nbp->rp; rlock(ifc); - if(ipv6anylocal(ifc, np->src)) { - netlog(f, Logicmp, "send icmphostunr -> s%I d%I\n", p->src, p->dst); - } + if(ipv6anylocal(ifc, np->src)) + netlog(f, Logicmp, "send icmphostunr -> s%I d%I\n", + p->src, p->dst); else { - netlog(f, Logicmp, "icmphostunr fail -> s%I d%I\n", p->src, p->dst); + netlog(f, Logicmp, "icmphostunr fail -> s%I d%I\n", + p->src, p->dst); freeblist(nbp); - if(free) + if(free) goto clean; else return; /n/sourcesdump/2007/0417/plan9/sys/src/9/ip/icmp6.c:476,502 - /n/sourcesdump/2007/0418/plan9/sys/src/9/ip/icmp6.c:462,489 extern void icmpttlexceeded6(Fs *f, Ipifc *ifc, Block *bp) { - Block *nbp; - IPICMP *np; - Ip6hdr *p; int osz = BLEN(bp); int sz = MIN(sizeof(IPICMP) + osz, v6MINTU); - Proto *icmp = f->t2p[ICMPv6]; + Block *nbp; + IPICMP *np; + Ip6hdr *p; + Proto *icmp = f->t2p[ICMPv6]; Icmppriv6 *ipriv = icmp->priv; - p = (Ip6hdr *) bp->rp; + p = (Ip6hdr *)bp->rp; - if(isv6mcast(p->src)) + if(isv6mcast(p->src)) return; nbp = newIPICMP(sz); np = (IPICMP *) nbp->rp; - if(ipv6anylocal(ifc, np->src)) { - netlog(f, Logicmp, "send icmpttlexceeded6 -> s%I d%I\n", p->src, p->dst); - } + if(ipv6anylocal(ifc, np->src)) + netlog(f, Logicmp, "send icmpttlexceeded6 -> s%I d%I\n", + p->src, p->dst); else { - netlog(f, Logicmp, "icmpttlexceeded6 fail -> s%I d%I\n", p->src, p->dst); + netlog(f, Logicmp, "icmpttlexceeded6 fail -> s%I d%I\n", + p->src, p->dst); return; } /n/sourcesdump/2007/0417/plan9/sys/src/9/ip/icmp6.c:514,540 - /n/sourcesdump/2007/0418/plan9/sys/src/9/ip/icmp6.c:501,528 extern void icmppkttoobig6(Fs *f, Ipifc *ifc, Block *bp) { - Block *nbp; - IPICMP *np; - Ip6hdr *p; int osz = BLEN(bp); int sz = MIN(sizeof(IPICMP) + osz, v6MINTU); - Proto *icmp = f->t2p[ICMPv6]; + Block *nbp; + IPICMP *np; + Ip6hdr *p; + Proto *icmp = f->t2p[ICMPv6]; Icmppriv6 *ipriv = icmp->priv; - p = (Ip6hdr *) bp->rp; + p = (Ip6hdr *)bp->rp; - if(isv6mcast(p->src)) + if(isv6mcast(p->src)) return; nbp = newIPICMP(sz); - np = (IPICMP *) nbp->rp; + np = (IPICMP *)nbp->rp; - if(ipv6anylocal(ifc, np->src)) { - netlog(f, Logicmp, "send icmppkttoobig6 -> s%I d%I\n", p->src, p->dst); - } + if(ipv6anylocal(ifc, np->src)) + netlog(f, Logicmp, "send icmppkttoobig6 -> s%I d%I\n", + p->src, p->dst); else { - netlog(f, Logicmp, "icmppkttoobig6 fail -> s%I d%I\n", p->src, p->dst); + netlog(f, Logicmp, "icmppkttoobig6 fail -> s%I d%I\n", + p->src, p->dst); return; } /n/sourcesdump/2007/0417/plan9/sys/src/9/ip/icmp6.c:554,565 - /n/sourcesdump/2007/0418/plan9/sys/src/9/ip/icmp6.c:542,554 * RFC 2461, pages 39-40, pages 57-58. */ static int - valid(Proto *icmp, Ipifc *ifc, Block *bp, Icmppriv6 *ipriv) { - int sz, osz, unsp, n, ttl, iplen; - int pktsz = BLEN(bp); - uchar *packet = bp->rp; - IPICMP *p = (IPICMP *) packet; - Ndpkt *np; + valid(Proto *icmp, Ipifc *ifc, Block *bp, Icmppriv6 *ipriv) + { + int sz, osz, unsp, n, ttl, iplen; + int pktsz = BLEN(bp); + uchar *packet = bp->rp; + IPICMP *p = (IPICMP *) packet; + Ndpkt *np; USED(ifc); n = blocklen(bp); /n/sourcesdump/2007/0417/plan9/sys/src/9/ip/icmp6.c:576,584 - /n/sourcesdump/2007/0418/plan9/sys/src/9/ip/icmp6.c:565,573 goto err; } - // Rather than construct explicit pseudoheader, overwrite IPv6 header + /* Rather than construct explicit pseudoheader, overwrite IPv6 header */ if(p->proto != ICMPv6) { - // This code assumes no extension headers!!! + /* This code assumes no extension headers!!! */ netlog(icmp->f, Logicmp, "icmp error: extension header\n"); goto err; } /n/sourcesdump/2007/0417/plan9/sys/src/9/ip/icmp6.c:595,613 - /n/sourcesdump/2007/0418/plan9/sys/src/9/ip/icmp6.c:584,599 p->ttl = ttl; /* additional tests for some pkt types */ - if( (p->type == NbrSolicit) || - (p->type == NbrAdvert) || - (p->type == RouterAdvert) || - (p->type == RouterSolicit) || - (p->type == RedirectV6) ) { - + if (p->type == NbrSolicit || p->type == NbrAdvert || + p->type == RouterAdvert || p->type == RouterSolicit || + p->type == RedirectV6) { if(p->ttl != HOP_LIMIT) { - ipriv->stats[HoplimErrs6]++; - goto err; + ipriv->stats[HoplimErrs6]++; + goto err; } if(p->code != 0) { - ipriv->stats[IcmpCodeErrs6]++; - goto err; + ipriv->stats[IcmpCodeErrs6]++; + goto err; } switch (p->type) { /n/sourcesdump/2007/0417/plan9/sys/src/9/ip/icmp6.c:615,687 - /n/sourcesdump/2007/0418/plan9/sys/src/9/ip/icmp6.c:601,671 case NbrAdvert: np = (Ndpkt*) p; if(isv6mcast(np->target)) { - ipriv->stats[TargetErrs6]++; - goto err; + ipriv->stats[TargetErrs6]++; + goto err; } - if(optexsts(np) && (np->olen == 0)) { - ipriv->stats[OptlenErrs6]++; - goto err; + if(optexsts(np) && np->olen == 0) { + ipriv->stats[OptlenErrs6]++; + goto err; } - - if(p->type == NbrSolicit) { - if(ipcmp(np->src, v6Unspecified) == 0) { - if(!issmcast(np->dst) || optexsts(np)) { - ipriv->stats[AddrmxpErrs6]++; + + if(p->type == NbrSolicit) + if(ipcmp(np->src, v6Unspecified) == 0) + if(!issmcast(np->dst) || optexsts(np)) { + ipriv->stats[AddrmxpErrs6]++; goto err; } + + if(p->type == NbrAdvert) + if(isv6mcast(np->dst) && + (nhgets(np->icmpid) & Sflag)){ + ipriv->stats[AddrmxpErrs6]++; + goto err; } - } - - if(p->type == NbrAdvert) { - if((isv6mcast(np->dst))&&(nhgets(np->icmpid) & Sflag)){ - ipriv->stats[AddrmxpErrs6]++; - goto err; - } - } break; - + case RouterAdvert: if(pktsz - sizeof(Ip6hdr) < 16) { - ipriv->stats[HlenErrs6]++; - goto err; + ipriv->stats[HlenErrs6]++; + goto err; } if(!islinklocal(p->src)) { - ipriv->stats[RouterAddrErrs6]++; - goto err; + ipriv->stats[RouterAddrErrs6]++; + goto err; } sz = sizeof(IPICMP) + 8; - while ((sz+1) < pktsz) { - osz = *(packet+sz+1); + while (sz+1 < pktsz) { + osz = packet[sz+1]; if(osz <= 0) { - ipriv->stats[OptlenErrs6]++; - goto err; - } + ipriv->stats[OptlenErrs6]++; + goto err; + } sz += 8*osz; } break; - + case RouterSolicit: if(pktsz - sizeof(Ip6hdr) < 8) { - ipriv->stats[HlenErrs6]++; - goto err; + ipriv->stats[HlenErrs6]++; + goto err; } unsp = (ipcmp(p->src, v6Unspecified) == 0); sz = sizeof(IPICMP) + 8; - while ((sz+1) < pktsz) { - osz = *(packet+sz+1); - if((osz <= 0) || - (unsp && (*(packet+sz) == slladd)) ) { - ipriv->stats[OptlenErrs6]++; - goto err; + while (sz+1 < pktsz) { + osz = packet[sz+1]; + if(osz <= 0 || + (unsp && packet[sz] == SRC_LLADDR)) { + ipriv->stats[OptlenErrs6]++; + goto err; } sz += 8*osz; } break; - + case RedirectV6: - //to be filled in + /* to be filled in */ break; - + default: goto err; } /n/sourcesdump/2007/0417/plan9/sys/src/9/ip/icmp6.c:690,696 - /n/sourcesdump/2007/0418/plan9/sys/src/9/ip/icmp6.c:674,680 return 1; err: - ipriv->stats[InErrors6]++; + ipriv->stats[InErrors6]++; return 0; } /n/sourcesdump/2007/0417/plan9/sys/src/9/ip/icmp6.c:706,718 - /n/sourcesdump/2007/0418/plan9/sys/src/9/ip/icmp6.c:690,701 return t_uniproxy; } - for(lifc = ifc->lifc; lifc; lifc = lifc->next) { + for(lifc = ifc->lifc; lifc; lifc = lifc->next) if(ipcmp(lifc->local, target) == 0) { - t = (lifc->tentative) ? t_unitent : t_unirany; + t = (lifc->tentative) ? t_unitent : t_unirany; runlock(ifc); return t; } - } runlock(ifc); return 0; /n/sourcesdump/2007/0417/plan9/sys/src/9/ip/icmp6.c:721,745 - /n/sourcesdump/2007/0418/plan9/sys/src/9/ip/icmp6.c:704,725 static void icmpiput6(Proto *icmp, Ipifc *ipifc, Block *bp) { - uchar *packet = bp->rp; - IPICMP *p = (IPICMP *)packet; - Icmppriv6 *ipriv = icmp->priv; - Block *r; - Proto *pr; - char *msg, m2[128]; - Ndpkt* np; + int refresh = 1; + char *msg, m2[128]; uchar pktflags; + uchar *packet = bp->rp; uchar lsrc[IPaddrlen]; - int refresh = 1; + Block *r; + IPICMP *p = (IPICMP *)packet; + Icmppriv6 *ipriv = icmp->priv; Iplifc *lifc; + Ndpkt* np; + Proto *pr; - if(!valid(icmp, ipifc, bp, ipriv)) + if(!valid(icmp, ipifc, bp, ipriv) || p->type > Maxtype6) goto raise; - if(p->type <= Maxtype6) - ipriv->in[p->type]++; - else - goto raise; + ipriv->in[p->type]++; switch(p->type) { case EchoRequestV6: /n/sourcesdump/2007/0417/plan9/sys/src/9/ip/icmp6.c:793,803 - /n/sourcesdump/2007/0418/plan9/sys/src/9/ip/icmp6.c:773,784 case RouterAdvert: case RouterSolicit: - /* using lsrc as a temp, munge hdr for goticmp6 - memmove(lsrc, p->src, IPaddrlen); - memmove(p->src, p->dst, IPaddrlen); - memmove(p->dst, lsrc, IPaddrlen); */ - + /* using lsrc as a temp, munge hdr for goticmp6 */ + if (0) { + memmove(lsrc, p->src, IPaddrlen); + memmove(p->src, p->dst, IPaddrlen); + memmove(p->dst, lsrc, IPaddrlen); + } goticmpkt6(icmp, bp, p->type); break; /n/sourcesdump/2007/0417/plan9/sys/src/9/ip/icmp6.c:809,824 - /n/sourcesdump/2007/0418/plan9/sys/src/9/ip/icmp6.c:790,806 pktflags |= Oflag; /* fall through */ - case t_uniproxy: + case t_uniproxy: if(ipcmp(np->src, v6Unspecified) != 0) { - arpenter(icmp->f, V6, np->src, np->lnaddr, 8*np->olen-2, 0); + arpenter(icmp->f, V6, np->src, np->lnaddr, + 8*np->olen-2, 0); pktflags |= Sflag; } - if(ipv6local(ipifc, lsrc)) { - icmpna(icmp->f, lsrc, - (ipcmp(np->src, v6Unspecified)==0)?v6allnodesL:np->src, - np->target, ipifc->mac, pktflags); - } + if(ipv6local(ipifc, lsrc)) + icmpna(icmp->f, lsrc, + (ipcmp(np->src, v6Unspecified) == 0? + v6allnodesL: np->src), + np->target, ipifc->mac, pktflags); else freeblist(bp); break; /n/sourcesdump/2007/0417/plan9/sys/src/9/ip/icmp6.c:826,856 - /n/sourcesdump/2007/0418/plan9/sys/src/9/ip/icmp6.c:808,837 case t_unitent: /* not clear what needs to be done. send up * an icmp mesg saying don't use this address? */ - default: freeblist(bp); } - break; case NbrAdvert: np = (Ndpkt*) p; - /* if the target address matches one of the local interface - * address and the local interface address has tentative bit set, - * then insert into ARP table. this is so the duplication address - * detection part of ipconfig can discover duplication through - * the arp table + /* + * if the target address matches one of the local interface + * addresses and the local interface address has tentative bit + * set, insert into ARP table. this is so the duplicate address + * detection part of ipconfig can discover duplication through + * the arp table. */ lifc = iplocalonifc(ipifc, np->target); if(lifc && lifc->tentative) refresh = 0; - arpenter(icmp->f, V6, np->target, np->lnaddr, 8*np->olen-2, refresh); + arpenter(icmp->f, V6, np->target, np->lnaddr, 8*np->olen-2, + refresh); freeblist(bp); break; case PacketTooBigV6: - default: goticmpkt6(icmp, bp, 0); break; /n/sourcesdump/2007/0417/plan9/sys/src/9/ip/icmp6.c:859,865 - /n/sourcesdump/2007/0418/plan9/sys/src/9/ip/icmp6.c:840,845 raise: freeblist(bp); - } int /n/sourcesdump/2007/0417/plan9/sys/src/9/ip/icmp6.c:874,891 - /n/sourcesdump/2007/0418/plan9/sys/src/9/ip/icmp6.c:854,872 e = p+len; for(i = 0; i < Nstats6; i++) p = seprint(p, e, "%s: %lud\n", statnames6[i], priv->stats[i]); - for(i = 0; i <= Maxtype6; i++){ + for(i = 0; i <= Maxtype6; i++) if(icmpnames6[i]) - p = seprint(p, e, "%s: %lud %lud\n", icmpnames6[i], priv->in[i], priv->out[i]); + p = seprint(p, e, "%s: %lud %lud\n", icmpnames6[i], + priv->in[i], priv->out[i]); /* else - p = seprint(p, e, "%d: %lud %lud\n", i, priv->in[i], priv->out[i]); - */ - } + p = seprint(p, e, "%d: %lud %lud\n", i, priv->in[i], + priv->out[i]); + */ return p - buf; } - // need to import from icmp.c + /* import from icmp.c */ extern int icmpstate(Conv *c, char *state, int n); extern char* icmpannounce(Conv *c, char **argv, int argc); extern char* icmpconnect(Conv *c, char **argv, int argc); /n/sourcesdump/2007/0417/plan9/sys/src/9/ip/icmp6.c:914,917 - /n/sourcesdump/2007/0418/plan9/sys/src/9/ip/icmp6.c:895,897 Fsproto(fs, icmp6); } - [geoff] --rw-rw-r-- M 64 presotto sys 4087 Apr 17 17:06 sys/src/9/ip/ipv6.h