Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. =================================================================== RCS file: /ftp/cvs/cvsroot/src/sys/netinet6/ip6_input.c,v rcsdiff: /ftp/cvs/cvsroot/src/sys/netinet6/ip6_input.c,v: warning: Unknown phrases like `commitid ...;' are present. retrieving revision 1.122.8.1.2.1 retrieving revision 1.132.2.2 diff -u -p -r1.122.8.1.2.1 -r1.132.2.2 --- src/sys/netinet6/ip6_input.c 2010/04/21 00:28:23 1.122.8.1.2.1 +++ src/sys/netinet6/ip6_input.c 2012/10/30 17:22:49 1.132.2.2 @@ -1,4 +1,4 @@ -/* $NetBSD: ip6_input.c,v 1.122.8.1.2.1 2010/04/21 00:28:23 matt Exp $ */ +/* $NetBSD: ip6_input.c,v 1.132.2.2 2012/10/30 17:22:49 yamt Exp $ */ /* $KAME: ip6_input.c,v 1.188 2001/03/29 05:34:31 itojun Exp $ */ /* @@ -62,12 +62,14 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: ip6_input.c,v 1.122.8.1.2.1 2010/04/21 00:28:23 matt Exp $"); +__KERNEL_RCSID(0, "$NetBSD: ip6_input.c,v 1.132.2.2 2012/10/30 17:22:49 yamt Exp $"); +#include "opt_gateway.h" #include "opt_inet.h" #include "opt_inet6.h" #include "opt_ipsec.h" #include "opt_pfil_hooks.h" +#include "opt_compat_netbsd.h" #include #include @@ -83,6 +85,7 @@ __KERNEL_RCSID(0, "$NetBSD: ip6_input.c, #include #include #include +#include #include #include @@ -100,6 +103,7 @@ __KERNEL_RCSID(0, "$NetBSD: ip6_input.c, #include #endif /* INET */ #include +#include #include #include #include @@ -109,17 +113,17 @@ __KERNEL_RCSID(0, "$NetBSD: ip6_input.c, #include #include -#ifdef IPSEC -#include -#include -#endif - #ifdef FAST_IPSEC #include #include #include #endif /* FAST_IPSEC */ +#ifdef COMPAT_50 +#include +#include +#endif + #include #include "faith.h" @@ -153,8 +157,10 @@ percpu_t *ip6stat_percpu; static void ip6_init2(void *); static struct m_tag *ip6_setdstifaddr(struct mbuf *, const struct in6_ifaddr *); -static int ip6_hopopts_input(u_int32_t *, u_int32_t *, struct mbuf **, int *); +static int ip6_process_hopopts(struct mbuf *, u_int8_t *, int, u_int32_t *, + u_int32_t *); static struct mbuf *ip6_pullexthdr(struct mbuf *, size_t, int); +static void sysctl_net_inet6_ip6_setup(struct sysctllog **); /* * IP6 initialization: fill in IP6 protocol switch table. @@ -166,6 +172,7 @@ ip6_init(void) const struct ip6protosw *pr; int i; + sysctl_net_inet6_ip6_setup(NULL); pr = (const struct ip6protosw *)pffindproto(PF_INET6, IPPROTO_RAW, SOCK_RAW); if (pr == 0) panic("ip6_init"); @@ -181,9 +188,9 @@ ip6_init(void) addrsel_policy_init(); nd6_init(); frag6_init(); - ip6_desync_factor = arc4random() % MAX_TEMP_DESYNC_FACTOR; + ip6_desync_factor = cprng_fast32() % MAX_TEMP_DESYNC_FACTOR; - ip6_init2((void *)0); + ip6_init2(NULL); #ifdef GATEWAY ip6flow_init(ip6_hashsize); #endif @@ -269,15 +276,6 @@ ip6_input(struct mbuf *m) int s, error; #endif -#ifdef IPSEC - /* - * should the inner packet be considered authentic? - * see comment in ah4_input(). - */ - m->m_flags &= ~M_AUTHIPHDR; - m->m_flags &= ~M_AUTHIPDGM; -#endif - /* * make sure we don't have onion peering information into m_tag. */ @@ -341,16 +339,11 @@ ip6_input(struct mbuf *m) goto bad; } -#if defined(IPSEC) - /* IPv6 fast forwarding is not compatible with IPsec. */ - m->m_flags &= ~M_CANFASTFWD; -#else /* * Assume that we can create a fast-forward IP flow entry * based on this packet. */ m->m_flags |= M_CANFASTFWD; -#endif #ifdef PFIL_HOOKS /* @@ -364,9 +357,7 @@ ip6_input(struct mbuf *m) * let ipfilter look at packet on the wire, * not the decapsulated packet. */ -#ifdef IPSEC - if (!ipsec_getnhist(m)) -#elif defined(FAST_IPSEC) +#if defined(FAST_IPSEC) if (!ipsec_indone(m)) #else if (1) @@ -775,18 +766,6 @@ ip6_input(struct mbuf *m) } } -#ifdef IPSEC - /* - * enforce IPsec policy checking if we are seeing last header. - * note that we do not visit this with protocols with pcb layer - * code - like udp/tcp/raw ip. - */ - if ((inet6sw[ip6_protox[nxt]].pr_flags & PR_LASTHDR) != 0 && - ipsec6_in_reject(m, NULL)) { - IPSEC6_STATINC(IPSEC_STAT_IN_POLVIO); - goto bad; - } -#endif #ifdef FAST_IPSEC /* * enforce IPsec policy checking if we are seeing last header. @@ -872,7 +851,7 @@ ip6_getdstifaddr(struct mbuf *m) * * rtalertp - XXX: should be stored more smart way */ -static int +int ip6_hopopts_input(u_int32_t *plenp, u_int32_t *rtalertp, struct mbuf **mp, int *offp) { @@ -917,7 +896,7 @@ ip6_hopopts_input(u_int32_t *plenp, u_in * (RFC2460 p7), opthead is pointer into data content in m, and opthead to * opthead + hbhlen is located in continuous memory region. */ -int +static int ip6_process_hopopts(struct mbuf *m, u_int8_t *opthead, int hbhlen, u_int32_t *rtalertp, u_int32_t *plenp) { @@ -954,7 +933,7 @@ ip6_process_hopopts(struct mbuf *m, u_in return (-1); } optlen = IP6OPT_RTALERT_LEN; - bcopy((void *)(opt + 2), (void *)&rtalert_val, 2); + memcpy((void *)&rtalert_val, (void *)(opt + 2), 2); *rtalertp = ntohs(rtalert_val); break; case IP6OPT_JUMBO: @@ -989,7 +968,7 @@ ip6_process_hopopts(struct mbuf *m, u_in * We may see jumbolen in unaligned location, so * we'd need to perform bcopy(). */ - bcopy(opt + 2, &jumboplen, sizeof(jumboplen)); + memcpy(&jumboplen, opt + 2, sizeof(jumboplen)); jumboplen = (u_int32_t)htonl(jumboplen); #if 1 @@ -1102,17 +1081,27 @@ ip6_savecontrol(struct in6pcb *in6p, str #define IS2292(x, y) (y) #endif -#ifdef SO_TIMESTAMP - if (in6p->in6p_socket->so_options & SO_TIMESTAMP) { + if (in6p->in6p_socket->so_options & SO_TIMESTAMP +#ifdef SO_OTIMESTAMP + || in6p->in6p_socket->so_options & SO_OTIMESTAMP +#endif + ) { struct timeval tv; microtime(&tv); +#ifdef SO_OTIMESTAMP + if (in6p->in6p_socket->so_options & SO_OTIMESTAMP) { + struct timeval50 tv50; + timeval_to_timeval50(&tv, &tv50); + *mp = sbcreatecontrol((void *) &tv50, sizeof(tv50), + SCM_OTIMESTAMP, SOL_SOCKET); + } else +#endif *mp = sbcreatecontrol((void *) &tv, sizeof(tv), SCM_TIMESTAMP, SOL_SOCKET); if (*mp) mp = &(*mp)->m_next; } -#endif /* some OSes call this logic with IPv4 packet, for SO_TIMESTAMP */ if ((ip6->ip6_vfc & IPV6_VERSION_MASK) != IPV6_VERSION) @@ -1122,7 +1111,7 @@ ip6_savecontrol(struct in6pcb *in6p, str if ((in6p->in6p_flags & IN6P_PKTINFO) != 0) { struct in6_pktinfo pi6; - bcopy(&ip6->ip6_dst, &pi6.ipi6_addr, sizeof(struct in6_addr)); + memcpy(&pi6.ipi6_addr, &ip6->ip6_dst, sizeof(struct in6_addr)); in6_clearscope(&pi6.ipi6_addr); /* XXX */ pi6.ipi6_ifindex = m->m_pkthdr.rcvif ? m->m_pkthdr.rcvif->if_index : 0; @@ -1562,7 +1551,7 @@ ip6_addaux(struct mbuf *m) M_NOWAIT); if (mtag) { m_tag_prepend(m, mtag); - bzero(mtag + 1, sizeof(struct ip6aux)); + memset(mtag + 1, 0, sizeof(struct ip6aux)); } } return mtag; @@ -1667,7 +1656,8 @@ sysctl_net_inet6_ip6_stats(SYSCTLFN_ARGS return (NETSTAT_SYSCTL(ip6stat_percpu, IP6_NSTATS)); } -SYSCTL_SETUP(sysctl_net_inet6_ip6_setup, "sysctl net.inet6.ip6 subtree setup") +static void +sysctl_net_inet6_ip6_setup(struct sysctllog **clog) { #ifdef RFC2292 #define IS2292(x, y) ((in6p->in6p_flags & IN6P_RFC2292) ? (x) : (y)) @@ -1773,6 +1763,20 @@ SYSCTL_SETUP(sysctl_net_inet6_ip6_setup, IPV6CTL_ACCEPT_RTADV, CTL_EOL); sysctl_createv(clog, 0, NULL, NULL, CTLFLAG_PERMANENT|CTLFLAG_READWRITE, + CTLTYPE_INT, "rtadv_maxroutes", + SYSCTL_DESCR("Maximum number of routes accepted via router advertisements"), + NULL, 0, &ip6_rtadv_maxroutes, 0, + CTL_NET, PF_INET6, IPPROTO_IPV6, + IPV6CTL_RTADV_MAXROUTES, CTL_EOL); + sysctl_createv(clog, 0, NULL, NULL, + CTLFLAG_PERMANENT, + CTLTYPE_INT, "rtadv_numroutes", + SYSCTL_DESCR("Current number of routes accepted via router advertisements"), + NULL, 0, &nd6_numroutes, 0, + CTL_NET, PF_INET6, IPPROTO_IPV6, + IPV6CTL_RTADV_NUMROUTES, CTL_EOL); + sysctl_createv(clog, 0, NULL, NULL, + CTLFLAG_PERMANENT|CTLFLAG_READWRITE, CTLTYPE_INT, "keepfaith", SYSCTL_DESCR("Activate faith interface"), NULL, 0, &ip6_keepfaith, 0, @@ -1953,6 +1957,58 @@ SYSCTL_SETUP(sysctl_net_inet6_ip6_setup, CTL_NET, PF_INET6, IPPROTO_IPV6, CTL_CREATE, CTL_EOL); #endif + /* anonportalgo RFC6056 subtree */ + const struct sysctlnode *portalgo_node; + sysctl_createv(clog, 0, NULL, &portalgo_node, + CTLFLAG_PERMANENT, + CTLTYPE_NODE, "anonportalgo", + SYSCTL_DESCR("Anonymous port algorithm selection (RFC 6056)"), + NULL, 0, NULL, 0, + CTL_NET, PF_INET6, IPPROTO_IPV6, CTL_CREATE, CTL_EOL); + sysctl_createv(clog, 0, &portalgo_node, NULL, + CTLFLAG_PERMANENT, + CTLTYPE_STRING, "available", + SYSCTL_DESCR("available algorithms"), + sysctl_portalgo_available, 0, NULL, PORTALGO_MAXLEN, + CTL_CREATE, CTL_EOL); + sysctl_createv(clog, 0, &portalgo_node, NULL, + CTLFLAG_PERMANENT|CTLFLAG_READWRITE, + CTLTYPE_STRING, "selected", + SYSCTL_DESCR("selected algorithm"), + sysctl_portalgo_selected6, 0, NULL, PORTALGO_MAXLEN, + CTL_CREATE, CTL_EOL); + sysctl_createv(clog, 0, NULL, NULL, + CTLFLAG_PERMANENT|CTLFLAG_READWRITE, + CTLTYPE_INT, "neighborgcthresh", + SYSCTL_DESCR("Maximum number of entries in neighbor" + " cache"), + NULL, 1, &ip6_neighborgcthresh, 0, + CTL_NET, PF_INET6, IPPROTO_IPV6, + CTL_CREATE, CTL_EOL); + sysctl_createv(clog, 0, NULL, NULL, + CTLFLAG_PERMANENT|CTLFLAG_READWRITE, + CTLTYPE_INT, "maxifprefixes", + SYSCTL_DESCR("Maximum number of prefixes created by" + " route advertisement per interface"), + NULL, 1, &ip6_maxifprefixes, 0, + CTL_NET, PF_INET6, IPPROTO_IPV6, + CTL_CREATE, CTL_EOL); + sysctl_createv(clog, 0, NULL, NULL, + CTLFLAG_PERMANENT|CTLFLAG_READWRITE, + CTLTYPE_INT, "maxifdefrouters", + SYSCTL_DESCR("Maximum number of default routers created" + " by route advertisement per interface"), + NULL, 1, &ip6_maxifdefrouters, 0, + CTL_NET, PF_INET6, IPPROTO_IPV6, + CTL_CREATE, CTL_EOL); + sysctl_createv(clog, 0, NULL, NULL, + CTLFLAG_PERMANENT|CTLFLAG_READWRITE, + CTLTYPE_INT, "maxdynroutes", + SYSCTL_DESCR("Maximum number of routes created via" + " redirect"), + NULL, 1, &ip6_maxdynroutes, 0, + CTL_NET, PF_INET6, IPPROTO_IPV6, + CTL_CREATE, CTL_EOL); } void