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/contrib/altq/altq/altq_subr.c | 3 +- sys/contrib/ipfilter/netinet/fil.c | 3 ++ sys/contrib/ipfilter/netinet/ip_fil_freebsd.c | 14 ++++++--- sys/contrib/pf/net/pf.c | 45 ++++++++++++++------------- sys/contrib/pf/net/pf_if.c | 5 +-- sys/contrib/pf/net/pf_ioctl.c | 3 +- sys/contrib/pf/net/pf_subr.c | 29 ++++++++--------- sys/contrib/rdma/rdma_cma.c | 17 +++++----- 8 files changed, 67 insertions(+), 52 deletions(-) (limited to 'sys/contrib') diff --git a/sys/contrib/altq/altq/altq_subr.c b/sys/contrib/altq/altq/altq_subr.c index c7c2f4a..af006a6 100644 --- a/sys/contrib/altq/altq/altq_subr.c +++ b/sys/contrib/altq/altq/altq_subr.c @@ -77,6 +77,7 @@ #include #include #include +#include #include #endif #if defined(__i386__) @@ -460,7 +461,7 @@ tbr_timeout(arg) #if defined(__FreeBSD__) && (__FreeBSD_version >= 500000) IFNET_RLOCK(); #endif - for (ifp = TAILQ_FIRST(&ifnet); ifp; ifp = TAILQ_NEXT(ifp, if_list)) { + for (ifp = TAILQ_FIRST(&V_ifnet); ifp; ifp = TAILQ_NEXT(ifp, if_list)) { /* read from if_snd unlocked */ if (!TBR_IS_ENABLED(&ifp->if_snd)) continue; diff --git a/sys/contrib/ipfilter/netinet/fil.c b/sys/contrib/ipfilter/netinet/fil.c index ea19254..3cd09d1 100644 --- a/sys/contrib/ipfilter/netinet/fil.c +++ b/sys/contrib/ipfilter/netinet/fil.c @@ -33,6 +33,9 @@ # if (__FreeBSD_version == 400019) # define CSUM_DELAY_DATA # endif +# if (__FreeBSD_version >= 800044) +# include +# endif # endif # include #else diff --git a/sys/contrib/ipfilter/netinet/ip_fil_freebsd.c b/sys/contrib/ipfilter/netinet/ip_fil_freebsd.c index 0eb2632..7bfd1de 100644 --- a/sys/contrib/ipfilter/netinet/ip_fil_freebsd.c +++ b/sys/contrib/ipfilter/netinet/ip_fil_freebsd.c @@ -62,6 +62,12 @@ static const char rcsid[] = "@(#)$Id: ip_fil_freebsd.c,v 2.53.2.50 2007/09/20 12 #else # include #endif +#if __FreeBSD_version >= 800044 +# include +#else +#define V_path_mtu_discovery path_mtu_discovery +#define V_ipforwarding ipforwarding +#endif #include #if __FreeBSD_version >= 300000 @@ -234,7 +240,7 @@ int ipfattach() fr_running = 1; if (fr_control_forwarding & 1) - ipforwarding = 1; + V_ipforwarding = 1; SPL_X(s); #if (__FreeBSD_version >= 300000) @@ -257,7 +263,7 @@ int ipfdetach() int s; #endif if (fr_control_forwarding & 2) - ipforwarding = 0; + V_ipforwarding = 0; SPL_NET(s); @@ -652,11 +658,11 @@ mb_t *m, **mpp; ip->ip_tos = oip->ip_tos; ip->ip_id = fin->fin_ip->ip_id; #if (__FreeBSD_version > 460000) - ip->ip_off = path_mtu_discovery ? IP_DF : 0; + ip->ip_off = V_path_mtu_discovery ? IP_DF : 0; #else ip->ip_off = 0; #endif - ip->ip_ttl = ip_defttl; + ip->ip_ttl = V_ip_defttl; ip->ip_sum = 0; hlen = sizeof(*oip); break; diff --git a/sys/contrib/pf/net/pf.c b/sys/contrib/pf/net/pf.c index 8289c99..35488ea 100644 --- a/sys/contrib/pf/net/pf.c +++ b/sys/contrib/pf/net/pf.c @@ -92,6 +92,7 @@ __FBSDID("$FreeBSD$"); #include #include #include +#include #else #include #endif @@ -1917,13 +1918,13 @@ pf_send_tcp(const struct pf_rule *r, sa_family_t af, h->ip_hl = sizeof(*h) >> 2; h->ip_tos = IPTOS_LOWDELAY; #ifdef __FreeBSD__ - h->ip_off = path_mtu_discovery ? IP_DF : 0; + h->ip_off = V_path_mtu_discovery ? IP_DF : 0; h->ip_len = len; #else h->ip_off = htons(ip_mtudisc ? IP_DF : 0); h->ip_len = htons(len); #endif - h->ip_ttl = ttl ? ttl : ip_defttl; + h->ip_ttl = ttl ? ttl : V_ip_defttl; h->ip_sum = 0; if (eh == NULL) { #ifdef __FreeBSD__ @@ -2954,7 +2955,7 @@ pf_socket_lookup(int direction, struct pf_pdesc *pd) sport = pd->hdr.tcp->th_sport; dport = pd->hdr.tcp->th_dport; #ifdef __FreeBSD__ - pi = &tcbinfo; + pi = &V_tcbinfo; #else tb = &tcbtable; #endif @@ -2965,7 +2966,7 @@ pf_socket_lookup(int direction, struct pf_pdesc *pd) sport = pd->hdr.udp->uh_sport; dport = pd->hdr.udp->uh_dport; #ifdef __FreeBSD__ - pi = &udbinfo; + pi = &V_udbinfo; #else tb = &udbtable; #endif @@ -3103,7 +3104,7 @@ pf_get_mss(struct mbuf *m, int off, u_int16_t th_off, sa_family_t af) int hlen; u_int8_t hdr[60]; u_int8_t *opt, optlen; - u_int16_t mss = tcp_mssdflt; + u_int16_t mss = V_tcp_mssdflt; hlen = th_off << 2; /* hlen <= sizeof(hdr) */ if (hlen <= sizeof(struct tcphdr)) @@ -3148,7 +3149,7 @@ pf_calc_mss(struct pf_addr *addr, sa_family_t af, u_int16_t offer) #endif /* INET6 */ struct rtentry *rt = NULL; int hlen = 0; /* make the compiler happy */ - u_int16_t mss = tcp_mssdflt; + u_int16_t mss = V_tcp_mssdflt; switch (af) { #ifdef INET @@ -3196,7 +3197,7 @@ pf_calc_mss(struct pf_addr *addr, sa_family_t af, u_int16_t offer) if (rt && rt->rt_ifp) { mss = rt->rt_ifp->if_mtu - hlen - sizeof(struct tcphdr); - mss = max(tcp_mssdflt, mss); + mss = max(V_tcp_mssdflt, mss); RTFREE(rt); } mss = min(mss, offer); @@ -3252,7 +3253,7 @@ pf_test_tcp(struct pf_rule **rm, struct pf_state **sm, int direction, u_short reason; int rewrite = 0; int tag = -1, rtableid = -1; - u_int16_t mss = tcp_mssdflt; + u_int16_t mss = V_tcp_mssdflt; int asd = 0; int match = 0; @@ -6152,7 +6153,7 @@ pf_route(struct mbuf **m, struct pf_rule *r, int dir, struct ifnet *oifp, if (r->rt == PF_FASTROUTE) { in_rtalloc(ro, 0); if (ro->ro_rt == 0) { - ipstat.ips_noroute++; + V_ipstat.ips_noroute++; goto bad; } @@ -6283,16 +6284,16 @@ pf_route(struct mbuf **m, struct pf_rule *r, int dir, struct ifnet *oifp, if ((ifp->if_capabilities & IFCAP_CSUM_IPv4) && ifp->if_bridge == NULL) { m0->m_pkthdr.csum_flags |= M_IPV4_CSUM_OUT; - ipstat.ips_outhwcsum++; + V_ipstat.ips_outhwcsum++; } else { ip->ip_sum = 0; ip->ip_sum = in_cksum(m0, ip->ip_hl << 2); } /* Update relevant hardware checksum stats for TCP/UDP */ if (m0->m_pkthdr.csum_flags & M_TCPV4_CSUM_OUT) - tcpstat.tcps_outhwcsum++; + V_tcpstat.tcps_outhwcsum++; else if (m0->m_pkthdr.csum_flags & M_UDPV4_CSUM_OUT) - udpstat.udps_outhwcsum++; + V_udpstat.udps_outhwcsum++; error = (*ifp->if_output)(ifp, m0, sintosa(dst), NULL); goto done; } @@ -6302,7 +6303,7 @@ pf_route(struct mbuf **m, struct pf_rule *r, int dir, struct ifnet *oifp, * Must be able to put at least 8 bytes per fragment. */ if (ip->ip_off & htons(IP_DF)) { - ipstat.ips_cantfrag++; + V_ipstat.ips_cantfrag++; if (r->rt != PF_DUPTO) { #ifdef __FreeBSD__ /* icmp_error() expects host byte ordering */ @@ -6359,7 +6360,7 @@ pf_route(struct mbuf **m, struct pf_rule *r, int dir, struct ifnet *oifp, } if (error == 0) - ipstat.ips_fragmented++; + V_ipstat.ips_fragmented++; done: if (r->rt != PF_DUPTO) @@ -6632,17 +6633,17 @@ pf_check_proto_cksum(struct mbuf *m, int off, int len, u_int8_t p, sa_family_t a if (sum) { switch (p) { case IPPROTO_TCP: - tcpstat.tcps_rcvbadsum++; + V_tcpstat.tcps_rcvbadsum++; break; case IPPROTO_UDP: - udpstat.udps_badsum++; + V_udpstat.udps_badsum++; break; case IPPROTO_ICMP: - icmpstat.icps_checksum++; + V_icmpstat.icps_checksum++; break; #ifdef INET6 case IPPROTO_ICMPV6: - icmp6stat.icp6s_checksum++; + V_icmp6stat.icp6s_checksum++; break; #endif /* INET6 */ } @@ -6728,17 +6729,17 @@ pf_check_proto_cksum(struct mbuf *m, int off, int len, u_int8_t p, m->m_pkthdr.csum_flags |= flag_bad; switch (p) { case IPPROTO_TCP: - tcpstat.tcps_rcvbadsum++; + V_tcpstat.tcps_rcvbadsum++; break; case IPPROTO_UDP: - udpstat.udps_badsum++; + V_udpstat.udps_badsum++; break; case IPPROTO_ICMP: - icmpstat.icps_checksum++; + V_icmpstat.icps_checksum++; break; #ifdef INET6 case IPPROTO_ICMPV6: - icmp6stat.icp6s_checksum++; + V_icmp6stat.icp6s_checksum++; break; #endif /* INET6 */ } diff --git a/sys/contrib/pf/net/pf_if.c b/sys/contrib/pf/net/pf_if.c index 2b82375..fd42dc7 100644 --- a/sys/contrib/pf/net/pf_if.c +++ b/sys/contrib/pf/net/pf_if.c @@ -54,6 +54,7 @@ __FBSDID("$FreeBSD$"); #include #endif #include +#include #include #include @@ -141,9 +142,9 @@ pfi_initialize(void) struct ifnet *ifp; IFNET_RLOCK(); - TAILQ_FOREACH(ifg, &ifg_head, ifg_next) + TAILQ_FOREACH(ifg, &V_ifg_head, ifg_next) pfi_attach_ifgroup(ifg); - TAILQ_FOREACH(ifp, &ifnet, if_link) + TAILQ_FOREACH(ifp, &V_ifnet, if_link) pfi_attach_ifnet(ifp); IFNET_RUNLOCK(); diff --git a/sys/contrib/pf/net/pf_ioctl.c b/sys/contrib/pf/net/pf_ioctl.c index 83a92df..3e99a99 100644 --- a/sys/contrib/pf/net/pf_ioctl.c +++ b/sys/contrib/pf/net/pf_ioctl.c @@ -86,6 +86,7 @@ __FBSDID("$FreeBSD$"); #include #include #include +#include #else #include #include @@ -3713,7 +3714,7 @@ pf_check6_in(void *arg, struct mbuf **m, struct ifnet *ifp, int dir, * order to support scoped addresses. In order to support stateful * filtering we have change this to lo0 as it is the case in IPv4. */ - chk = pf_test6(PF_IN, (*m)->m_flags & M_LOOP ? &loif[0] : ifp, m, + chk = pf_test6(PF_IN, (*m)->m_flags & M_LOOP ? &V_loif[0] : ifp, m, NULL, inp); if (chk && *m) { m_freem(*m); diff --git a/sys/contrib/pf/net/pf_subr.c b/sys/contrib/pf/net/pf_subr.c index 7d87833..f8550c7 100644 --- a/sys/contrib/pf/net/pf_subr.c +++ b/sys/contrib/pf/net/pf_subr.c @@ -45,6 +45,7 @@ __FBSDID("$FreeBSD$"); #include #include #include +#include #include #include @@ -127,9 +128,9 @@ pf_new_isn(struct pf_state *s) struct pf_state_host *src, *dst; /* Seed if this is the first use, reseed if requested. */ - if (isn_last_reseed == 0) { - read_random(&isn_secret, sizeof(isn_secret)); - isn_last_reseed = ticks; + if (V_isn_last_reseed == 0) { + read_random(&V_isn_secret, sizeof(V_isn_secret)); + V_isn_last_reseed = ticks; } if (s->direction == PF_IN) { @@ -141,28 +142,28 @@ pf_new_isn(struct pf_state *s) } /* Compute the md5 hash and return the ISN. */ - MD5Init(&isn_ctx); - MD5Update(&isn_ctx, (u_char *) &dst->port, sizeof(u_short)); - MD5Update(&isn_ctx, (u_char *) &src->port, sizeof(u_short)); + MD5Init(&V_isn_ctx); + MD5Update(&V_isn_ctx, (u_char *) &dst->port, sizeof(u_short)); + MD5Update(&V_isn_ctx, (u_char *) &src->port, sizeof(u_short)); #ifdef INET6 if (s->af == AF_INET6) { - MD5Update(&isn_ctx, (u_char *) &dst->addr, + MD5Update(&V_isn_ctx, (u_char *) &dst->addr, sizeof(struct in6_addr)); - MD5Update(&isn_ctx, (u_char *) &src->addr, + MD5Update(&V_isn_ctx, (u_char *) &src->addr, sizeof(struct in6_addr)); } else #endif { - MD5Update(&isn_ctx, (u_char *) &dst->addr, + MD5Update(&V_isn_ctx, (u_char *) &dst->addr, sizeof(struct in_addr)); - MD5Update(&isn_ctx, (u_char *) &src->addr, + MD5Update(&V_isn_ctx, (u_char *) &src->addr, sizeof(struct in_addr)); } - MD5Update(&isn_ctx, (u_char *) &isn_secret, sizeof(isn_secret)); - MD5Final((u_char *) &md5_buffer, &isn_ctx); + MD5Update(&V_isn_ctx, (u_char *) &V_isn_secret, sizeof(V_isn_secret)); + MD5Final((u_char *) &md5_buffer, &V_isn_ctx); new_isn = (tcp_seq) md5_buffer[0]; - isn_offset += ISN_STATIC_INCREMENT + + V_isn_offset += ISN_STATIC_INCREMENT + (arc4random() & ISN_RANDOM_INCREMENT); - new_isn += isn_offset; + new_isn += V_isn_offset; return (new_isn); } diff --git a/sys/contrib/rdma/rdma_cma.c b/sys/contrib/rdma/rdma_cma.c index 8dddf6c..fa93816 100644 --- a/sys/contrib/rdma/rdma_cma.c +++ b/sys/contrib/rdma/rdma_cma.c @@ -46,6 +46,7 @@ __FBSDID("$FreeBSD$"); #include #include #include +#include #include #include @@ -1962,18 +1963,18 @@ retry: if (ret) goto err1; - if (port > ipport_lastauto) { - if (next_port != ipport_firstauto) { + if (port > V_ipport_lastauto) { + if (next_port != V_ipport_firstauto) { kvl_delete(ps, port); - next_port = ipport_firstauto; + next_port = V_ipport_firstauto; goto retry; } ret = EADDRNOTAVAIL; goto err2; } - if (port == ipport_lastauto) - next_port = ipport_firstauto; + if (port == V_ipport_lastauto) + next_port = V_ipport_firstauto; else next_port = port + 1; @@ -1997,7 +1998,7 @@ static int cma_use_port(struct kvl *ps, struct rdma_id_private *id_priv) sin = (struct sockaddr_in *) &id_priv->id.route.addr.src_addr; snum = ntohs(sin->sin_port); - if (snum <= ipport_reservedhigh && snum >= ipport_reservedlow && + if (snum <= V_ipport_reservedhigh && snum >= V_ipport_reservedlow && priv_check(curthread, PRIV_NETINET_RESERVEDPORT)) return (EACCES); @@ -2917,8 +2918,8 @@ static int cma_init(void) arc4rand(&next_port, sizeof next_port, 0); next_port = ((unsigned int) next_port % - (ipport_lastauto - ipport_firstauto)) + - ipport_firstauto; + (V_ipport_lastauto - V_ipport_firstauto)) + + V_ipport_firstauto; cma_wq = taskqueue_create("rdma_cm", M_NOWAIT, taskqueue_thread_enqueue, &cma_wq); -- cgit v1.1