From 1021d43b569bfc8d2c5544bde2f540fa432b011f Mon Sep 17 00:00:00 2001 From: bz Date: Sun, 17 Aug 2008 23:27:27 +0000 Subject: Commit step 1 of the vimage project, (network stack) virtualization work done by Marko Zec (zec@). This is the first in a series of commits over the course of the next few weeks. Mark all uses of global variables to be virtualized with a V_ prefix. Use macros to map them back to their global names for now, so this is a NOP change only. We hope to have caught at least 85-90% of what is needed so we do not invalidate a lot of outstanding patches again. Obtained from: //depot/projects/vimage-commit2/... Reviewed by: brooks, des, ed, mav, julian, jamie, kris, rwatson, zec, ... (various people I forgot, different versions) md5 (with a bit of help) Sponsored by: NLnet Foundation, The FreeBSD Foundation X-MFC after: never V_Commit_Message_Reviewed_By: more people than the patch --- sys/netinet6/ip6_input.c | 153 ++++++++++++++++++++++++----------------------- 1 file changed, 77 insertions(+), 76 deletions(-) (limited to 'sys/netinet6/ip6_input.c') diff --git a/sys/netinet6/ip6_input.c b/sys/netinet6/ip6_input.c index e6ca375..6bd9557 100644 --- a/sys/netinet6/ip6_input.c +++ b/sys/netinet6/ip6_input.c @@ -80,6 +80,7 @@ __FBSDID("$FreeBSD$"); #include #include #include +#include #include #include @@ -178,14 +179,14 @@ ip6_init(void) printf("%s: WARNING: unable to register pfil hook, " "error %d\n", __func__, i); - ip6intrq.ifq_maxlen = ip6qmaxlen; + ip6intrq.ifq_maxlen = V_ip6qmaxlen; mtx_init(&ip6intrq.ifq_mtx, "ip6_inq", NULL, MTX_DEF); netisr_register(NETISR_IPV6, ip6_input, &ip6intrq, 0); scope6_init(); addrsel_policy_init(); nd6_init(); frag6_init(); - ip6_desync_factor = arc4random() % MAX_TEMP_DESYNC_FACTOR; + V_ip6_desync_factor = arc4random() % MAX_TEMP_DESYNC_FACTOR; } static void @@ -193,14 +194,14 @@ ip6_init2(void *dummy) { /* nd6_timer_init */ - callout_init(&nd6_timer_ch, 0); - callout_reset(&nd6_timer_ch, hz, nd6_timer, NULL); + callout_init(&V_nd6_timer_ch, 0); + callout_reset(&V_nd6_timer_ch, hz, nd6_timer, NULL); /* timer for regeneranation of temporary addresses randomize ID */ - callout_init(&in6_tmpaddrtimer_ch, 0); - callout_reset(&in6_tmpaddrtimer_ch, - (ip6_temp_preferred_lifetime - ip6_desync_factor - - ip6_temp_regen_advance) * hz, + callout_init(&V_in6_tmpaddrtimer_ch, 0); + callout_reset(&V_in6_tmpaddrtimer_ch, + (V_ip6_temp_preferred_lifetime - V_ip6_desync_factor - + V_ip6_temp_regen_advance) * hz, in6_tmpaddrtimer, NULL); } @@ -244,20 +245,20 @@ ip6_input(struct mbuf *m) */ if (m->m_flags & M_EXT) { if (m->m_next) - ip6stat.ip6s_mext2m++; + V_ip6stat.ip6s_mext2m++; else - ip6stat.ip6s_mext1++; + V_ip6stat.ip6s_mext1++; } else { -#define M2MMAX (sizeof(ip6stat.ip6s_m2m)/sizeof(ip6stat.ip6s_m2m[0])) +#define M2MMAX (sizeof(V_ip6stat.ip6s_m2m)/sizeof(V_ip6stat.ip6s_m2m[0])) if (m->m_next) { if (m->m_flags & M_LOOP) { - ip6stat.ip6s_m2m[loif[0].if_index]++; /* XXX */ + V_ip6stat.ip6s_m2m[V_loif[0].if_index]++; /* XXX */ } else if (m->m_pkthdr.rcvif->if_index < M2MMAX) - ip6stat.ip6s_m2m[m->m_pkthdr.rcvif->if_index]++; + V_ip6stat.ip6s_m2m[m->m_pkthdr.rcvif->if_index]++; else - ip6stat.ip6s_m2m[0]++; + V_ip6stat.ip6s_m2m[0]++; } else - ip6stat.ip6s_m1++; + V_ip6stat.ip6s_m1++; #undef M2MMAX } @@ -268,7 +269,7 @@ ip6_input(struct mbuf *m) } in6_ifstat_inc(m->m_pkthdr.rcvif, ifs6_in_receive); - ip6stat.ip6s_total++; + V_ip6stat.ip6s_total++; #ifndef PULLDOWN_TEST /* @@ -306,7 +307,7 @@ ip6_input(struct mbuf *m) struct ifnet *inifp; inifp = m->m_pkthdr.rcvif; if ((m = m_pullup(m, sizeof(struct ip6_hdr))) == NULL) { - ip6stat.ip6s_toosmall++; + V_ip6stat.ip6s_toosmall++; in6_ifstat_inc(inifp, ifs6_in_hdrerr); return; } @@ -315,12 +316,12 @@ ip6_input(struct mbuf *m) ip6 = mtod(m, struct ip6_hdr *); if ((ip6->ip6_vfc & IPV6_VERSION_MASK) != IPV6_VERSION) { - ip6stat.ip6s_badvers++; + V_ip6stat.ip6s_badvers++; in6_ifstat_inc(m->m_pkthdr.rcvif, ifs6_in_hdrerr); goto bad; } - ip6stat.ip6s_nxthist[ip6->ip6_nxt]++; + V_ip6stat.ip6s_nxthist[ip6->ip6_nxt]++; /* * Check against address spoofing/corruption. @@ -330,7 +331,7 @@ ip6_input(struct mbuf *m) /* * XXX: "badscope" is not very suitable for a multicast source. */ - ip6stat.ip6s_badscope++; + V_ip6stat.ip6s_badscope++; in6_ifstat_inc(m->m_pkthdr.rcvif, ifs6_in_addrerr); goto bad; } @@ -342,7 +343,7 @@ ip6_input(struct mbuf *m) * because ip6_mloopback() passes the "actual" interface * as the outgoing/incoming interface. */ - ip6stat.ip6s_badscope++; + V_ip6stat.ip6s_badscope++; in6_ifstat_inc(m->m_pkthdr.rcvif, ifs6_in_addrerr); goto bad; } @@ -367,7 +368,7 @@ ip6_input(struct mbuf *m) */ if (IN6_IS_ADDR_V4MAPPED(&ip6->ip6_src) || IN6_IS_ADDR_V4MAPPED(&ip6->ip6_dst)) { - ip6stat.ip6s_badscope++; + V_ip6stat.ip6s_badscope++; in6_ifstat_inc(m->m_pkthdr.rcvif, ifs6_in_addrerr); goto bad; } @@ -381,7 +382,7 @@ ip6_input(struct mbuf *m) */ if (IN6_IS_ADDR_V4COMPAT(&ip6->ip6_src) || IN6_IS_ADDR_V4COMPAT(&ip6->ip6_dst)) { - ip6stat.ip6s_badscope++; + V_ip6stat.ip6s_badscope++; in6_ifstat_inc(m->m_pkthdr.rcvif, ifs6_in_addrerr); goto bad; } @@ -419,12 +420,12 @@ passin: * is not loopback. */ if (in6_clearscope(&ip6->ip6_src) || in6_clearscope(&ip6->ip6_dst)) { - ip6stat.ip6s_badscope++; /* XXX */ + V_ip6stat.ip6s_badscope++; /* XXX */ goto bad; } if (in6_setscope(&ip6->ip6_src, m->m_pkthdr.rcvif, NULL) || in6_setscope(&ip6->ip6_dst, m->m_pkthdr.rcvif, NULL)) { - ip6stat.ip6s_badscope++; + V_ip6stat.ip6s_badscope++; goto bad; } @@ -443,8 +444,8 @@ passin: if (in6m) ours = 1; else if (!ip6_mrouter) { - ip6stat.ip6s_notmember++; - ip6stat.ip6s_cantforward++; + V_ip6stat.ip6s_notmember++; + V_ip6stat.ip6s_cantforward++; in6_ifstat_inc(m->m_pkthdr.rcvif, ifs6_in_discard); goto bad; } @@ -455,28 +456,28 @@ passin: /* * Unicast check */ - if (ip6_forward_rt.ro_rt != NULL && - (ip6_forward_rt.ro_rt->rt_flags & RTF_UP) != 0 && + if (V_ip6_forward_rt.ro_rt != NULL && + (V_ip6_forward_rt.ro_rt->rt_flags & RTF_UP) != 0 && IN6_ARE_ADDR_EQUAL(&ip6->ip6_dst, - &((struct sockaddr_in6 *)(&ip6_forward_rt.ro_dst))->sin6_addr)) - ip6stat.ip6s_forward_cachehit++; + &((struct sockaddr_in6 *)(&V_ip6_forward_rt.ro_dst))->sin6_addr)) + V_ip6stat.ip6s_forward_cachehit++; else { struct sockaddr_in6 *dst6; - if (ip6_forward_rt.ro_rt) { + if (V_ip6_forward_rt.ro_rt) { /* route is down or destination is different */ - ip6stat.ip6s_forward_cachemiss++; - RTFREE(ip6_forward_rt.ro_rt); - ip6_forward_rt.ro_rt = 0; + V_ip6stat.ip6s_forward_cachemiss++; + RTFREE(V_ip6_forward_rt.ro_rt); + V_ip6_forward_rt.ro_rt = 0; } - bzero(&ip6_forward_rt.ro_dst, sizeof(struct sockaddr_in6)); - dst6 = (struct sockaddr_in6 *)&ip6_forward_rt.ro_dst; + bzero(&V_ip6_forward_rt.ro_dst, sizeof(struct sockaddr_in6)); + dst6 = (struct sockaddr_in6 *)&V_ip6_forward_rt.ro_dst; dst6->sin6_len = sizeof(struct sockaddr_in6); dst6->sin6_family = AF_INET6; dst6->sin6_addr = ip6->ip6_dst; - rtalloc((struct route *)&ip6_forward_rt); + rtalloc((struct route *)&V_ip6_forward_rt); } #define rt6_key(r) ((struct sockaddr_in6 *)((r)->rt_nodes->rn_key)) @@ -501,14 +502,14 @@ passin: * while it would be less efficient. Or, should we rather install a * reject route for such a case? */ - if (ip6_forward_rt.ro_rt && - (ip6_forward_rt.ro_rt->rt_flags & + if (V_ip6_forward_rt.ro_rt && + (V_ip6_forward_rt.ro_rt->rt_flags & (RTF_HOST|RTF_GATEWAY)) == RTF_HOST && #ifdef RTF_WASCLONED - !(ip6_forward_rt.ro_rt->rt_flags & RTF_WASCLONED) && + !(V_ip6_forward_rt.ro_rt->rt_flags & RTF_WASCLONED) && #endif #ifdef RTF_CLONED - !(ip6_forward_rt.ro_rt->rt_flags & RTF_CLONED) && + !(V_ip6_forward_rt.ro_rt->rt_flags & RTF_CLONED) && #endif #if 0 /* @@ -517,11 +518,11 @@ passin: * already done through looking up the routing table. */ IN6_ARE_ADDR_EQUAL(&ip6->ip6_dst, - &rt6_key(ip6_forward_rt.ro_rt)->sin6_addr) + &rt6_key(V_ip6_forward_rt.ro_rt)->sin6_addr) #endif - ip6_forward_rt.ro_rt->rt_ifp->if_type == IFT_LOOP) { + V_ip6_forward_rt.ro_rt->rt_ifp->if_type == IFT_LOOP) { struct in6_ifaddr *ia6 = - (struct in6_ifaddr *)ip6_forward_rt.ro_rt->rt_ifa; + (struct in6_ifaddr *)V_ip6_forward_rt.ro_rt->rt_ifa; /* * record address information into m_tag. @@ -556,12 +557,12 @@ passin: /* * FAITH (Firewall Aided Internet Translator) */ - if (ip6_keepfaith) { - if (ip6_forward_rt.ro_rt && ip6_forward_rt.ro_rt->rt_ifp - && ip6_forward_rt.ro_rt->rt_ifp->if_type == IFT_FAITH) { + if (V_ip6_keepfaith) { + if (V_ip6_forward_rt.ro_rt && V_ip6_forward_rt.ro_rt->rt_ifp + && V_ip6_forward_rt.ro_rt->rt_ifp->if_type == IFT_FAITH) { /* XXX do we need more sanity checks? */ ours = 1; - deliverifp = ip6_forward_rt.ro_rt->rt_ifp; /* faith */ + deliverifp = V_ip6_forward_rt.ro_rt->rt_ifp; /* faith */ goto hbhcheck; } } @@ -570,8 +571,8 @@ passin: * Now there is no reason to process the packet if it's not our own * and we're not a router. */ - if (!ip6_forwarding) { - ip6stat.ip6s_cantforward++; + if (!V_ip6_forwarding) { + V_ip6stat.ip6s_cantforward++; in6_ifstat_inc(m->m_pkthdr.rcvif, ifs6_in_discard); goto bad; } @@ -628,7 +629,7 @@ passin: * contained, ip6_hopopts_input() must set a valid * (non-zero) payload length to the variable plen. */ - ip6stat.ip6s_badoptions++; + V_ip6stat.ip6s_badoptions++; in6_ifstat_inc(m->m_pkthdr.rcvif, ifs6_in_discard); in6_ifstat_inc(m->m_pkthdr.rcvif, ifs6_in_hdrerr); icmp6_error(m, ICMP6_PARAM_PROB, @@ -643,7 +644,7 @@ passin: IP6_EXTHDR_GET(hbh, struct ip6_hbh *, m, sizeof(struct ip6_hdr), sizeof(struct ip6_hbh)); if (hbh == NULL) { - ip6stat.ip6s_tooshort++; + V_ip6stat.ip6s_tooshort++; return; } #endif @@ -656,7 +657,7 @@ passin: * case we should pass the packet to the multicast routing * daemon. */ - if (rtalert != ~0 && ip6_forwarding) { + if (rtalert != ~0 && V_ip6_forwarding) { switch (rtalert) { case IP6OPT_RTALERT_MLD: ours = 1; @@ -679,7 +680,7 @@ passin: * Drop packet if shorter than we expect. */ if (m->m_pkthdr.len - sizeof(struct ip6_hdr) < plen) { - ip6stat.ip6s_tooshort++; + V_ip6stat.ip6s_tooshort++; in6_ifstat_inc(m->m_pkthdr.rcvif, ifs6_in_truncated); goto bad; } @@ -705,7 +706,7 @@ passin: */ if (ip6_mrouter && ip6_mforward && ip6_mforward(ip6, m->m_pkthdr.rcvif, m)) { - ip6stat.ip6s_cantforward++; + V_ip6stat.ip6s_cantforward++; m_freem(m); return; } @@ -731,7 +732,7 @@ passin: */ if (IN6_IS_ADDR_V4MAPPED(&ip6->ip6_src) || IN6_IS_ADDR_V4MAPPED(&ip6->ip6_dst)) { - ip6stat.ip6s_badscope++; + V_ip6stat.ip6s_badscope++; in6_ifstat_inc(m->m_pkthdr.rcvif, ifs6_in_addrerr); goto bad; } @@ -739,13 +740,13 @@ passin: /* * Tell launch routine the next header */ - ip6stat.ip6s_delivered++; + V_ip6stat.ip6s_delivered++; in6_ifstat_inc(deliverifp, ifs6_in_deliver); nest = 0; while (nxt != IPPROTO_DONE) { - if (ip6_hdrnestlimit && (++nest > ip6_hdrnestlimit)) { - ip6stat.ip6s_toomanyhdr++; + if (V_ip6_hdrnestlimit && (++nest > V_ip6_hdrnestlimit)) { + V_ip6stat.ip6s_toomanyhdr++; goto bad; } @@ -754,7 +755,7 @@ passin: * more sanity checks in header chain processing. */ if (m->m_pkthdr.len < off) { - ip6stat.ip6s_tooshort++; + V_ip6stat.ip6s_tooshort++; in6_ifstat_inc(m->m_pkthdr.rcvif, ifs6_in_truncated); goto bad; } @@ -829,14 +830,14 @@ ip6_hopopts_input(u_int32_t *plenp, u_int32_t *rtalertp, IP6_EXTHDR_GET(hbh, struct ip6_hbh *, m, sizeof(struct ip6_hdr), sizeof(struct ip6_hbh)); if (hbh == NULL) { - ip6stat.ip6s_tooshort++; + V_ip6stat.ip6s_tooshort++; return -1; } hbhlen = (hbh->ip6h_len + 1) << 3; IP6_EXTHDR_GET(hbh, struct ip6_hbh *, m, sizeof(struct ip6_hdr), hbhlen); if (hbh == NULL) { - ip6stat.ip6s_tooshort++; + V_ip6stat.ip6s_tooshort++; return -1; } #endif @@ -881,7 +882,7 @@ ip6_process_hopopts(struct mbuf *m, u_int8_t *opthead, int hbhlen, break; case IP6OPT_PADN: if (hbhlen < IP6OPT_MINLEN) { - ip6stat.ip6s_toosmall++; + V_ip6stat.ip6s_toosmall++; goto bad; } optlen = *(opt + 1) + 2; @@ -889,7 +890,7 @@ ip6_process_hopopts(struct mbuf *m, u_int8_t *opthead, int hbhlen, case IP6OPT_ROUTER_ALERT: /* XXX may need check for alignment */ if (hbhlen < IP6OPT_RTALERT_LEN) { - ip6stat.ip6s_toosmall++; + V_ip6stat.ip6s_toosmall++; goto bad; } if (*(opt + 1) != IP6OPT_RTALERT_LEN - 2) { @@ -906,7 +907,7 @@ ip6_process_hopopts(struct mbuf *m, u_int8_t *opthead, int hbhlen, case IP6OPT_JUMBO: /* XXX may need check for alignment */ if (hbhlen < IP6OPT_JUMBO_LEN) { - ip6stat.ip6s_toosmall++; + V_ip6stat.ip6s_toosmall++; goto bad; } if (*(opt + 1) != IP6OPT_JUMBO_LEN - 2) { @@ -924,7 +925,7 @@ ip6_process_hopopts(struct mbuf *m, u_int8_t *opthead, int hbhlen, */ ip6 = mtod(m, struct ip6_hdr *); if (ip6->ip6_plen) { - ip6stat.ip6s_badoptions++; + V_ip6stat.ip6s_badoptions++; icmp6_error(m, ICMP6_PARAM_PROB, ICMP6_PARAMPROB_HEADER, erroff + opt - opthead); @@ -948,7 +949,7 @@ ip6_process_hopopts(struct mbuf *m, u_int8_t *opthead, int hbhlen, * there's no explicit mention in specification. */ if (*plenp != 0) { - ip6stat.ip6s_badoptions++; + V_ip6stat.ip6s_badoptions++; icmp6_error(m, ICMP6_PARAM_PROB, ICMP6_PARAMPROB_HEADER, erroff + opt + 2 - opthead); @@ -960,7 +961,7 @@ ip6_process_hopopts(struct mbuf *m, u_int8_t *opthead, int hbhlen, * jumbo payload length must be larger than 65535. */ if (jumboplen <= IPV6_MAXPACKET) { - ip6stat.ip6s_badoptions++; + V_ip6stat.ip6s_badoptions++; icmp6_error(m, ICMP6_PARAM_PROB, ICMP6_PARAMPROB_HEADER, erroff + opt + 2 - opthead); @@ -971,7 +972,7 @@ ip6_process_hopopts(struct mbuf *m, u_int8_t *opthead, int hbhlen, break; default: /* unknown option */ if (hbhlen < IP6OPT_MINLEN) { - ip6stat.ip6s_toosmall++; + V_ip6stat.ip6s_toosmall++; goto bad; } optlen = ip6_unknown_opt(opt, m, @@ -1008,11 +1009,11 @@ ip6_unknown_opt(u_int8_t *optp, struct mbuf *m, int off) m_freem(m); return (-1); case IP6OPT_TYPE_FORCEICMP: /* send ICMP even if multicasted */ - ip6stat.ip6s_badoptions++; + V_ip6stat.ip6s_badoptions++; icmp6_error(m, ICMP6_PARAM_PROB, ICMP6_PARAMPROB_OPTION, off); return (-1); case IP6OPT_TYPE_ICMP: /* send ICMP if not multicasted */ - ip6stat.ip6s_badoptions++; + V_ip6stat.ip6s_badoptions++; ip6 = mtod(m, struct ip6_hdr *); if (IN6_IS_ADDR_MULTICAST(&ip6->ip6_dst) || (m->m_flags & (M_BCAST|M_MCAST))) @@ -1151,14 +1152,14 @@ ip6_savecontrol(struct inpcb *in6p, struct mbuf *m, struct mbuf **mp) ext = ip6_pullexthdr(m, sizeof(struct ip6_hdr), ip6->ip6_nxt); if (ext == NULL) { - ip6stat.ip6s_tooshort++; + V_ip6stat.ip6s_tooshort++; return; } hbh = mtod(ext, struct ip6_hbh *); hbhlen = (hbh->ip6h_len + 1) << 3; if (hbhlen != ext->m_len) { m_freem(ext); - ip6stat.ip6s_tooshort++; + V_ip6stat.ip6s_tooshort++; return; } #endif @@ -1225,7 +1226,7 @@ ip6_savecontrol(struct inpcb *in6p, struct mbuf *m, struct mbuf **mp) #else ext = ip6_pullexthdr(m, off, nxt); if (ext == NULL) { - ip6stat.ip6s_tooshort++; + V_ip6stat.ip6s_tooshort++; return; } ip6e = mtod(ext, struct ip6_ext *); @@ -1235,7 +1236,7 @@ ip6_savecontrol(struct inpcb *in6p, struct mbuf *m, struct mbuf **mp) elen = (ip6e->ip6e_len + 1) << 3; if (elen != ext->m_len) { m_freem(ext); - ip6stat.ip6s_tooshort++; + V_ip6stat.ip6s_tooshort++; return; } #endif -- cgit v1.1