diff options
author | Bjoern A. Zeeb <bz@FreeBSD.org> | 2008-08-17 23:27:27 +0000 |
---|---|---|
committer | Bjoern A. Zeeb <bz@FreeBSD.org> | 2008-08-17 23:27:27 +0000 |
commit | 603724d3abed34351087e20b8cb363d8e02072c1 (patch) | |
tree | 1496da534aec03cf2f9d2d0735d80e4c1e3b5715 /sys/netinet/ip_divert.c | |
parent | ac2dcb729fc5b54bc829c23d239dec65a057bf49 (diff) | |
download | src-603724d3abed34351087e20b8cb363d8e02072c1.tar.gz src-603724d3abed34351087e20b8cb363d8e02072c1.zip |
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
Notes
Notes:
svn path=/head/; revision=181803
Diffstat (limited to 'sys/netinet/ip_divert.c')
-rw-r--r-- | sys/netinet/ip_divert.c | 91 |
1 files changed, 46 insertions, 45 deletions
diff --git a/sys/netinet/ip_divert.c b/sys/netinet/ip_divert.c index a5091519f843..1bba15ac0261 100644 --- a/sys/netinet/ip_divert.c +++ b/sys/netinet/ip_divert.c @@ -58,6 +58,7 @@ __FBSDID("$FreeBSD$"); #include <sys/sx.h> #include <sys/sysctl.h> #include <sys/systm.h> +#include <sys/vimage.h> #include <vm/uma.h> @@ -124,7 +125,7 @@ static void div_zone_change(void *tag) { - uma_zone_set_max(divcbinfo.ipi_zone, maxsockets); + uma_zone_set_max(V_divcbinfo.ipi_zone, maxsockets); } static int @@ -148,18 +149,18 @@ void div_init(void) { - INP_INFO_LOCK_INIT(&divcbinfo, "div"); - LIST_INIT(&divcb); - divcbinfo.ipi_listhead = &divcb; + INP_INFO_LOCK_INIT(&V_divcbinfo, "div"); + LIST_INIT(&V_divcb); + V_divcbinfo.ipi_listhead = &V_divcb; /* * XXX We don't use the hash list for divert IP, but it's easier * to allocate a one entry hash list than it is to check all * over the place for hashbase == NULL. */ - divcbinfo.ipi_hashbase = hashinit(1, M_PCB, &divcbinfo.ipi_hashmask); - divcbinfo.ipi_porthashbase = hashinit(1, M_PCB, - &divcbinfo.ipi_porthashmask); - divcbinfo.ipi_zone = uma_zcreate("divcb", sizeof(struct inpcb), + V_divcbinfo.ipi_hashbase = hashinit(1, M_PCB, &V_divcbinfo.ipi_hashmask); + V_divcbinfo.ipi_porthashbase = hashinit(1, M_PCB, + &V_divcbinfo.ipi_porthashmask); + V_divcbinfo.ipi_zone = uma_zcreate("divcb", sizeof(struct inpcb), NULL, NULL, div_inpcb_init, div_inpcb_fini, UMA_ALIGN_PTR, UMA_ZONE_NOFREE); uma_zone_set_max(divcbinfo.ipi_zone, maxsockets); @@ -174,7 +175,7 @@ div_init(void) void div_input(struct mbuf *m, int off) { - ipstat.ips_noproto++; + V_ipstat.ips_noproto++; m_freem(m); } @@ -266,8 +267,8 @@ divert_packet(struct mbuf *m, int incoming) /* Put packet on socket queue, if any */ sa = NULL; nport = htons((u_int16_t)divert_info(mtag)); - INP_INFO_RLOCK(&divcbinfo); - LIST_FOREACH(inp, &divcb, inp_list) { + INP_INFO_RLOCK(&V_divcbinfo); + LIST_FOREACH(inp, &V_divcb, inp_list) { /* XXX why does only one socket match? */ if (inp->inp_lport == nport) { INP_RLOCK(inp); @@ -284,11 +285,11 @@ divert_packet(struct mbuf *m, int incoming) break; } } - INP_INFO_RUNLOCK(&divcbinfo); + INP_INFO_RUNLOCK(&V_divcbinfo); if (sa == NULL) { m_freem(m); - ipstat.ips_noproto++; - ipstat.ips_delivered--; + V_ipstat.ips_noproto++; + V_ipstat.ips_delivered--; } } @@ -353,7 +354,7 @@ div_output(struct socket *so, struct mbuf *m, struct sockaddr_in *sin, struct inpcb *inp; dt->info |= IP_FW_DIVERT_OUTPUT_FLAG; - INP_INFO_WLOCK(&divcbinfo); + INP_INFO_WLOCK(&V_divcbinfo); inp = sotoinpcb(so); INP_RLOCK(inp); /* @@ -364,7 +365,7 @@ div_output(struct socket *so, struct mbuf *m, struct sockaddr_in *sin, ((u_short)ntohs(ip->ip_len) > m->m_pkthdr.len)) { error = EINVAL; INP_RUNLOCK(inp); - INP_INFO_WUNLOCK(&divcbinfo); + INP_INFO_WUNLOCK(&V_divcbinfo); m_freem(m); } else { /* Convert fields to host order for ip_output() */ @@ -372,7 +373,7 @@ div_output(struct socket *so, struct mbuf *m, struct sockaddr_in *sin, ip->ip_off = ntohs(ip->ip_off); /* Send packet to output processing */ - ipstat.ips_rawout++; /* XXX */ + V_ipstat.ips_rawout++; /* XXX */ #ifdef MAC mac_inpcb_create_mbuf(inp, m); @@ -405,7 +406,7 @@ div_output(struct socket *so, struct mbuf *m, struct sockaddr_in *sin, error = ENOBUFS; } INP_RUNLOCK(inp); - INP_INFO_WUNLOCK(&divcbinfo); + INP_INFO_WUNLOCK(&V_divcbinfo); if (error == ENOBUFS) { m_freem(m); return (error); @@ -468,14 +469,14 @@ div_attach(struct socket *so, int proto, struct thread *td) error = soreserve(so, div_sendspace, div_recvspace); if (error) return error; - INP_INFO_WLOCK(&divcbinfo); - error = in_pcballoc(so, &divcbinfo); + INP_INFO_WLOCK(&V_divcbinfo); + error = in_pcballoc(so, &V_divcbinfo); if (error) { - INP_INFO_WUNLOCK(&divcbinfo); + INP_INFO_WUNLOCK(&V_divcbinfo); return error; } inp = (struct inpcb *)so->so_pcb; - INP_INFO_WUNLOCK(&divcbinfo); + INP_INFO_WUNLOCK(&V_divcbinfo); inp->inp_ip_p = proto; inp->inp_vflag |= INP_IPV4; inp->inp_flags |= INP_HDRINCL; @@ -490,11 +491,11 @@ div_detach(struct socket *so) inp = sotoinpcb(so); KASSERT(inp != NULL, ("div_detach: inp == NULL")); - INP_INFO_WLOCK(&divcbinfo); + INP_INFO_WLOCK(&V_divcbinfo); INP_WLOCK(inp); in_pcbdetach(inp); in_pcbfree(inp); - INP_INFO_WUNLOCK(&divcbinfo); + INP_INFO_WUNLOCK(&V_divcbinfo); } static int @@ -515,11 +516,11 @@ div_bind(struct socket *so, struct sockaddr *nam, struct thread *td) if (nam->sa_family != AF_INET) return EAFNOSUPPORT; ((struct sockaddr_in *)nam)->sin_addr.s_addr = INADDR_ANY; - INP_INFO_WLOCK(&divcbinfo); + INP_INFO_WLOCK(&V_divcbinfo); INP_WLOCK(inp); error = in_pcbbind(inp, nam, td->td_ucred); INP_WUNLOCK(inp); - INP_INFO_WUNLOCK(&divcbinfo); + INP_INFO_WUNLOCK(&V_divcbinfo); return error; } @@ -543,7 +544,7 @@ div_send(struct socket *so, int flags, struct mbuf *m, struct sockaddr *nam, /* Packet must have a header (but that's about it) */ if (m->m_len < sizeof (struct ip) && (m = m_pullup(m, sizeof (struct ip))) == 0) { - ipstat.ips_toosmall++; + V_ipstat.ips_toosmall++; m_freem(m); return EINVAL; } @@ -577,7 +578,7 @@ div_pcblist(SYSCTL_HANDLER_ARGS) * resource-intensive to repeat twice on every request. */ if (req->oldptr == 0) { - n = divcbinfo.ipi_count; + n = V_divcbinfo.ipi_count; req->oldidx = 2 * (sizeof xig) + (n + n/8) * sizeof(struct xinpcb); return 0; @@ -589,10 +590,10 @@ div_pcblist(SYSCTL_HANDLER_ARGS) /* * OK, now we're committed to doing something. */ - INP_INFO_RLOCK(&divcbinfo); - gencnt = divcbinfo.ipi_gencnt; - n = divcbinfo.ipi_count; - INP_INFO_RUNLOCK(&divcbinfo); + INP_INFO_RLOCK(&V_divcbinfo); + gencnt = V_divcbinfo.ipi_gencnt; + n = V_divcbinfo.ipi_count; + INP_INFO_RUNLOCK(&V_divcbinfo); error = sysctl_wire_old_buffer(req, 2 * sizeof(xig) + n*sizeof(struct xinpcb)); @@ -611,8 +612,8 @@ div_pcblist(SYSCTL_HANDLER_ARGS) if (inp_list == 0) return ENOMEM; - INP_INFO_RLOCK(&divcbinfo); - for (inp = LIST_FIRST(divcbinfo.ipi_listhead), i = 0; inp && i < n; + INP_INFO_RLOCK(&V_divcbinfo); + for (inp = LIST_FIRST(V_divcbinfo.ipi_listhead), i = 0; inp && i < n; inp = LIST_NEXT(inp, inp_list)) { INP_RLOCK(inp); if (inp->inp_gencnt <= gencnt && @@ -620,7 +621,7 @@ div_pcblist(SYSCTL_HANDLER_ARGS) inp_list[i++] = inp; INP_RUNLOCK(inp); } - INP_INFO_RUNLOCK(&divcbinfo); + INP_INFO_RUNLOCK(&V_divcbinfo); n = i; error = 0; @@ -648,11 +649,11 @@ div_pcblist(SYSCTL_HANDLER_ARGS) * while we were processing this request, and it * might be necessary to retry. */ - INP_INFO_RLOCK(&divcbinfo); - xig.xig_gen = divcbinfo.ipi_gencnt; + INP_INFO_RLOCK(&V_divcbinfo); + xig.xig_gen = V_divcbinfo.ipi_gencnt; xig.xig_sogen = so_gencnt; - xig.xig_count = divcbinfo.ipi_count; - INP_INFO_RUNLOCK(&divcbinfo); + xig.xig_count = V_divcbinfo.ipi_count; + INP_INFO_RUNLOCK(&V_divcbinfo); error = SYSCTL_OUT(req, &xig, sizeof xig); } free(inp_list, M_TEMP); @@ -724,18 +725,18 @@ div_modevent(module_t mod, int type, void *unused) * socket open request could be spinning on the lock and then * we destroy the lock. */ - INP_INFO_WLOCK(&divcbinfo); - n = divcbinfo.ipi_count; + INP_INFO_WLOCK(&V_divcbinfo); + n = V_divcbinfo.ipi_count; if (n != 0) { err = EBUSY; - INP_INFO_WUNLOCK(&divcbinfo); + INP_INFO_WUNLOCK(&V_divcbinfo); break; } ip_divert_ptr = NULL; err = pf_proto_unregister(PF_INET, IPPROTO_DIVERT, SOCK_RAW); - INP_INFO_WUNLOCK(&divcbinfo); - INP_INFO_LOCK_DESTROY(&divcbinfo); - uma_zdestroy(divcbinfo.ipi_zone); + INP_INFO_WUNLOCK(&V_divcbinfo); + INP_INFO_LOCK_DESTROY(&V_divcbinfo); + uma_zdestroy(V_divcbinfo.ipi_zone); break; default: err = EOPNOTSUPP; |