Skip to content

Commit

Permalink
Step 1.5 of importing the network stack virtualization infrastructure
Browse files Browse the repository at this point in the history
from the vimage project, as per plan established at devsummit 08/08:
http://wiki.freebsd.org/Image/Notes200808DevSummit

Introduce INIT_VNET_*() initializer macros, VNET_FOREACH() iterator
macros, and CURVNET_SET() context setting macros, all currently
resolving to NOPs.

Prepare for virtualization of selected SYSCTL objects by introducing a
family of SYSCTL_V_*() macros, currently resolving to their global
counterparts, i.e. SYSCTL_V_INT() == SYSCTL_INT().

Move selected #defines from sys/sys/vimage.h to newly introduced header
files specific to virtualized subsystems (sys/net/vnet.h,
sys/netinet/vinet.h etc.).

All the changes are verified to have zero functional impact at this
point in time by doing MD5 comparision between pre- and post-change
object files(*).

(*) netipsec/keysock.c did not validate depending on compile time options.

Implemented by:	julian, bz, brooks, zec
Reviewed by:	julian, bz, brooks, kris, rwatson, ...
Approved by:	julian (mentor)
Obtained from:	//depot/projects/vimage-commit2/...
X-MFC after:	never
Sponsored by:	NLnet Foundation, The FreeBSD Foundation
  • Loading branch information
gornjas committed Oct 2, 2008
1 parent e682bfa commit 8797d4c
Show file tree
Hide file tree
Showing 125 changed files with 2,728 additions and 901 deletions.
1 change: 1 addition & 0 deletions sys/compat/linprocfs/linprocfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -1001,6 +1001,7 @@ linprocfs_doprocmaps(PFS_FILL_ARGS)
static int
linprocfs_donetdev(PFS_FILL_ARGS)
{
INIT_VNET_NET(TD_TO_VNET(curthread));
char ifname[16]; /* XXX LINUX_IFNAMSIZ */
struct ifnet *ifp;

Expand Down
3 changes: 3 additions & 0 deletions sys/compat/linux/linux_ioctl.c
Original file line number Diff line number Diff line change
Expand Up @@ -2051,6 +2051,7 @@ linux_ioctl_console(struct thread *td, struct linux_ioctl_args *args)
int
linux_ifname(struct ifnet *ifp, char *buffer, size_t buflen)
{
INIT_VNET_NET(ifp->if_vnet);
struct ifnet *ifscan;
int ethno;

Expand Down Expand Up @@ -2084,6 +2085,7 @@ linux_ifname(struct ifnet *ifp, char *buffer, size_t buflen)
static struct ifnet *
ifname_linux_to_bsd(const char *lxname, char *bsdname)
{
INIT_VNET_NET(TD_TO_VNET(curthread));
struct ifnet *ifp;
int len, unit;
char *ep;
Expand Down Expand Up @@ -2124,6 +2126,7 @@ ifname_linux_to_bsd(const char *lxname, char *bsdname)
static int
linux_ifconf(struct thread *td, struct ifconf *uifc)
{
INIT_VNET_NET(TD_TO_VNET(td));
#ifdef COMPAT_LINUX32
struct l_ifconf ifc;
#else
Expand Down
1 change: 1 addition & 0 deletions sys/compat/linux/linux_misc.c
Original file line number Diff line number Diff line change
Expand Up @@ -707,6 +707,7 @@ linux_times(struct thread *td, struct linux_times_args *args)
int
linux_newuname(struct thread *td, struct linux_newuname_args *args)
{
INIT_VPROCG(TD_TO_VPROCG(td));
struct l_new_utsname utsname;
char osname[LINUX_MAX_UTSNAME];
char osrelease[LINUX_MAX_UTSNAME];
Expand Down
3 changes: 3 additions & 0 deletions sys/compat/linux/linux_socket.c
Original file line number Diff line number Diff line change
Expand Up @@ -546,6 +546,9 @@ struct linux_socket_args {
static int
linux_socket(struct thread *td, struct linux_socket_args *args)
{
#ifdef INET6
INIT_VNET_INET6(curvnet);
#endif
struct socket_args /* {
int domain;
int type;
Expand Down
1 change: 1 addition & 0 deletions sys/compat/svr4/svr4_sockio.c
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ svr4_sock_ioctl(fp, td, retval, fd, cmd, data)
switch (cmd) {
case SVR4_SIOCGIFNUM:
{
INIT_VNET_NET(curvnet);
struct ifnet *ifp;
struct ifaddr *ifa;
int ifnum = 0;
Expand Down
5 changes: 5 additions & 0 deletions sys/contrib/ipfilter/netinet/ip_auth.c
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,11 @@ struct file;
#include <netinet/in.h>
#include <netinet/in_systm.h>
#include <netinet/ip.h>
#if !defined(_KERNEL) && defined(__FreeBSD_version) && \
__FreeBSD_version >= 800049
# define V_ip_do_randomid ip_do_randomid
# define V_ip_id ip_id
#endif
#if !defined(_KERNEL) && !defined(__osf__) && !defined(__sgi)
# define KERNEL
# define _KERNEL
Expand Down
18 changes: 18 additions & 0 deletions sys/contrib/pf/net/pf.c
Original file line number Diff line number Diff line change
Expand Up @@ -1759,6 +1759,7 @@ pf_send_tcp(const struct pf_rule *r, sa_family_t af,
u_int8_t flags, u_int16_t win, u_int16_t mss, u_int8_t ttl, int tag,
u_int16_t rtag, struct ether_header *eh, struct ifnet *ifp)
{
INIT_VNET_INET(curvnet);
struct mbuf *m;
int len, tlen;
#ifdef INET
Expand Down Expand Up @@ -2922,6 +2923,7 @@ pf_socket_lookup(int direction, struct pf_pdesc *pd, struct inpcb *inp_arg)
pf_socket_lookup(int direction, struct pf_pdesc *pd)
#endif
{
INIT_VNET_INET(curvnet);
struct pf_addr *saddr, *daddr;
u_int16_t sport, dport;
#ifdef __FreeBSD__
Expand Down Expand Up @@ -3101,6 +3103,7 @@ pf_get_wscale(struct mbuf *m, int off, u_int16_t th_off, sa_family_t af)
u_int16_t
pf_get_mss(struct mbuf *m, int off, u_int16_t th_off, sa_family_t af)
{
INIT_VNET_INET(curvnet);
int hlen;
u_int8_t hdr[60];
u_int8_t *opt, optlen;
Expand Down Expand Up @@ -3140,6 +3143,7 @@ u_int16_t
pf_calc_mss(struct pf_addr *addr, sa_family_t af, u_int16_t offer)
{
#ifdef INET
INIT_VNET_INET(curvnet);
struct sockaddr_in *dst;
struct route ro;
#endif /* INET */
Expand Down Expand Up @@ -3242,6 +3246,7 @@ pf_test_tcp(struct pf_rule **rm, struct pf_state **sm, int direction,
struct ifqueue *ifq)
#endif
{
INIT_VNET_INET(curvnet);
struct pf_rule *nr = NULL;
struct pf_addr *saddr = pd->src, *daddr = pd->dst;
struct tcphdr *th = pd->hdr.tcp;
Expand Down Expand Up @@ -6096,6 +6101,7 @@ void
pf_route(struct mbuf **m, struct pf_rule *r, int dir, struct ifnet *oifp,
struct pf_state *s, struct pf_pdesc *pd)
{
INIT_VNET_INET(curvnet);
struct mbuf *m0, *m1;
struct route iproute;
struct route *ro = NULL;
Expand Down Expand Up @@ -6633,18 +6639,30 @@ 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:
{
INIT_VNET_INET(curvnet);
V_tcpstat.tcps_rcvbadsum++;
break;
}
case IPPROTO_UDP:
{
INIT_VNET_INET(curvnet);
V_udpstat.udps_badsum++;
break;
}
case IPPROTO_ICMP:
{
INIT_VNET_INET(curvnet);
V_icmpstat.icps_checksum++;
break;
}
#ifdef INET6
case IPPROTO_ICMPV6:
{
INIT_VNET_INET6(curvnet);
V_icmp6stat.icp6s_checksum++;
break;
}
#endif /* INET6 */
}
return (1);
Expand Down
2 changes: 2 additions & 0 deletions sys/contrib/pf/net/pf_if.c
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,8 @@ RB_GENERATE(pfi_ifhead, pfi_kif, pfik_tree, pfi_if_compare);
void
pfi_initialize(void)
{
INIT_VNET_NET(curvnet);

if (pfi_all != NULL) /* already initialized */
return;

Expand Down
2 changes: 2 additions & 0 deletions sys/contrib/pf/net/pf_ioctl.c
Original file line number Diff line number Diff line change
Expand Up @@ -3704,6 +3704,8 @@ static int
pf_check6_in(void *arg, struct mbuf **m, struct ifnet *ifp, int dir,
struct inpcb *inp)
{
INIT_VNET_NET(curvnet);

/*
* IPv6 is not affected by ip_len/ip_off byte order changes.
*/
Expand Down
1 change: 1 addition & 0 deletions sys/contrib/pf/net/pf_subr.c
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ static MD5_CTX isn_ctx;
u_int32_t
pf_new_isn(struct pf_state *s)
{
INIT_VNET_INET(curvnet);
u_int32_t md5_buffer[4];
u_int32_t new_isn;
struct pf_state_host *src, *dst;
Expand Down
7 changes: 7 additions & 0 deletions sys/contrib/pf/net/pfvar.h
Original file line number Diff line number Diff line change
Expand Up @@ -1855,5 +1855,12 @@ int pf_osfp_match(struct pf_osfp_enlist *, pf_osfp_t);
struct pf_os_fingerprint *
pf_osfp_validate(void);

/*
* Symbol translation macros
*/
#define INIT_VNET_PF(vnet) \
INIT_FROM_VNET(vnet, VNET_MOD_PF, struct vnet_pf, vnet_pf)

#define VNET_PF(sym) VSYM(vnet_pf, sym)

#endif /* _NET_PFVAR_H_ */
4 changes: 4 additions & 0 deletions sys/contrib/rdma/rdma_cma.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ __FBSDID("$FreeBSD$");
#include <sys/syslog.h>
#include <sys/vimage.h>

#include <net/if.h>
#include <netinet/in.h>
#include <netinet/in_pcb.h>

Expand Down Expand Up @@ -1947,6 +1948,7 @@ static int cma_alloc_port(struct kvl *ps, struct rdma_id_private *id_priv,

static int cma_alloc_any_port(struct kvl *ps, struct rdma_id_private *id_priv)
{
INIT_VNET_INET(curvnet);
struct rdma_bind_list *bind_list;
int port, ret;

Expand Down Expand Up @@ -1991,6 +1993,7 @@ static int cma_alloc_any_port(struct kvl *ps, struct rdma_id_private *id_priv)

static int cma_use_port(struct kvl *ps, struct rdma_id_private *id_priv)
{
INIT_VNET_INET(curvnet);
struct rdma_id_private *cur_id;
struct sockaddr_in *sin, *cur_sin;
struct rdma_bind_list *bind_list;
Expand Down Expand Up @@ -2910,6 +2913,7 @@ static void cma_remove_one(struct ib_device *device)

static int cma_init(void)
{
INIT_VNET_INET(curvnet);
int ret;

LIST_INIT(&listen_any_list);
Expand Down
11 changes: 9 additions & 2 deletions sys/dev/cxgb/ulp/iw_cxgb/iw_cxgb.c
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,7 @@ ifaddr_event_handler(void *arg, struct ifnet *ifp)
static int
iwch_init_module(void)
{
VNET_ITERATOR_DECL(vnet_iter);
int err;
struct ifnet *ifp;

Expand All @@ -233,9 +234,15 @@ iwch_init_module(void)

/* Register existing TOE interfaces by walking the ifnet chain */
IFNET_RLOCK();
TAILQ_FOREACH(ifp, &V_ifnet, if_link) {
(void)ifaddr_event_handler(NULL, ifp);
VNET_LIST_RLOCK();
VNET_FOREACH(vnet_iter) {
CURVNET_SET(vnet_iter); /* XXX CURVNET_SET_QUIET() ? */
INIT_VNET_NET(vnet_iter);
TAILQ_FOREACH(ifp, &V_ifnet, if_link)
(void)ifaddr_event_handler(NULL, ifp);
CURVNET_RESTORE();
}
VNET_LIST_RUNLOCK();
IFNET_RUNLOCK();
return 0;
}
Expand Down
4 changes: 4 additions & 0 deletions sys/dev/cxgb/ulp/tom/cxgb_cpl_io.c
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,7 @@ mk_tid_release(struct mbuf *m, const struct toepcb *toep, unsigned int tid)
static inline void
make_tx_data_wr(struct socket *so, struct mbuf *m, int len, struct mbuf *tail)
{
INIT_VNET_INET(so->so_vnet);
struct tcpcb *tp = so_sototcpcb(so);
struct toepcb *toep = tp->t_toe;
struct tx_data_wr *req;
Expand Down Expand Up @@ -1220,6 +1221,7 @@ install_offload_ops(struct socket *so)
static __inline int
select_rcv_wscale(int space)
{
INIT_VNET_INET(so->so_vnet);
int wscale = 0;

if (space > MAX_RCV_WND)
Expand All @@ -1237,6 +1239,7 @@ select_rcv_wscale(int space)
static unsigned long
select_rcv_wnd(struct toedev *dev, struct socket *so)
{
INIT_VNET_INET(so->so_vnet);
struct tom_data *d = TOM_DATA(dev);
unsigned int wnd;
unsigned int max_rcv_wnd;
Expand Down Expand Up @@ -3783,6 +3786,7 @@ fixup_and_send_ofo(struct toepcb *toep)
static void
socket_act_establish(struct socket *so, struct mbuf *m)
{
INIT_VNET_INET(so->so_vnet);
struct cpl_act_establish *req = cplhdr(m);
u32 rcv_isn = ntohl(req->rcv_isn); /* real RCV_ISN + 1 */
struct tcpcb *tp = so_sototcpcb(so);
Expand Down
2 changes: 1 addition & 1 deletion sys/dev/firewire/firewire.c
Original file line number Diff line number Diff line change
Expand Up @@ -703,7 +703,7 @@ fw_reset_crom(struct firewire_comm *fc)
crom_add_simple_text(src, root, &buf->vendor, "FreeBSD Project");
crom_add_entry(root, CSRKEY_HW, __FreeBSD_version);
#endif
crom_add_simple_text(src, root, &buf->hw, V_hostname);
crom_add_simple_text(src, root, &buf->hw, G_hostname);
}

/*
Expand Down
2 changes: 2 additions & 0 deletions sys/fs/cd9660/cd9660_rrip.c
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ cd9660_rrip_slink(p,ana)
ISO_RRIP_SLINK *p;
ISO_RRIP_ANALYZE *ana;
{
INIT_VPROCG(TD_TO_VPROCG(curthread));
ISO_RRIP_SLINK_COMPONENT *pcomp;
ISO_RRIP_SLINK_COMPONENT *pcompe;
int len, wlen, cont;
Expand Down Expand Up @@ -224,6 +225,7 @@ cd9660_rrip_altname(p,ana)
ISO_RRIP_ALTNAME *p;
ISO_RRIP_ANALYZE *ana;
{
INIT_VPROCG(TD_TO_VPROCG(curthread));
char *inbuf;
int wlen;
int cont;
Expand Down
1 change: 1 addition & 0 deletions sys/kern/kern_jail.c
Original file line number Diff line number Diff line change
Expand Up @@ -475,6 +475,7 @@ jailed(struct ucred *cred)
void
getcredhostname(struct ucred *cred, char *buf, size_t size)
{
INIT_VPROCG(cred->cr_vimage->v_procg);

if (jailed(cred)) {
mtx_lock(&cred->cr_prison->pr_mtx);
Expand Down
9 changes: 7 additions & 2 deletions sys/kern/kern_mib.c
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,9 @@ static char machine_arch[] = MACHINE_ARCH;
SYSCTL_STRING(_hw, HW_MACHINE_ARCH, machine_arch, CTLFLAG_RD,
machine_arch, 0, "System architecture");

#ifndef VIMAGE
char hostname[MAXHOSTNAMELEN];
#endif

/*
* This mutex is used to protect the hostname and domainname variables, and
Expand All @@ -219,6 +221,7 @@ MTX_SYSINIT(hostname_mtx, &hostname_mtx, "hostname", MTX_DEF);
static int
sysctl_hostname(SYSCTL_HANDLER_ARGS)
{
INIT_VPROCG(TD_TO_VPROCG(req->td));
struct prison *pr;
char tmphostname[MAXHOSTNAMELEN];
int error;
Expand Down Expand Up @@ -345,7 +348,9 @@ SYSCTL_PROC(_kern, OID_AUTO, conftxt, CTLTYPE_STRING|CTLFLAG_RW,
0, 0, sysctl_kern_config, "", "Kernel configuration file");
#endif

#ifndef VIMAGE
char domainname[MAXHOSTNAMELEN]; /* Protected by hostname_mtx. */
#endif

static int
sysctl_domainname(SYSCTL_HANDLER_ARGS)
Expand All @@ -354,13 +359,13 @@ sysctl_domainname(SYSCTL_HANDLER_ARGS)
int error;

mtx_lock(&hostname_mtx);
bcopy(domainname, tmpdomainname, MAXHOSTNAMELEN);
bcopy(V_domainname, tmpdomainname, MAXHOSTNAMELEN);
mtx_unlock(&hostname_mtx);
error = sysctl_handle_string(oidp, tmpdomainname,
sizeof tmpdomainname, req);
if (req->newptr != NULL && error == 0) {
mtx_lock(&hostname_mtx);
bcopy(tmpdomainname, domainname, MAXHOSTNAMELEN);
bcopy(tmpdomainname, V_domainname, MAXHOSTNAMELEN);
mtx_unlock(&hostname_mtx);
}
return (error);
Expand Down
1 change: 1 addition & 0 deletions sys/kern/kern_uuid.c
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ MTX_SYSINIT(uuid_lock, &uuid_mutex, "UUID generator mutex lock", MTX_DEF);
static void
uuid_node(uint16_t *node)
{
INIT_VNET_NET(curvnet);
struct ifnet *ifp;
struct ifaddr *ifa;
struct sockaddr_dl *sdl;
Expand Down
4 changes: 3 additions & 1 deletion sys/kern/kern_xxx.c
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,7 @@ getdomainname(td, uap)
struct thread *td;
struct getdomainname_args *uap;
{
INIT_VPROCG(TD_TO_VPROCG(td));
char tmpdomainname[MAXHOSTNAMELEN];
int domainnamelen;

Expand All @@ -271,6 +272,7 @@ setdomainname(td, uap)
struct thread *td;
struct setdomainname_args *uap;
{
INIT_VPROCG(TD_TO_VPROCG(td));
char tmpdomainname[MAXHOSTNAMELEN];
int error, domainnamelen;

Expand All @@ -284,7 +286,7 @@ setdomainname(td, uap)
if (error == 0) {
tmpdomainname[domainnamelen] = 0;
mtx_lock(&hostname_mtx);
bcopy(tmpdomainname, V_domainname, sizeof(domainname));
bcopy(tmpdomainname, V_domainname, sizeof(V_domainname));
mtx_unlock(&hostname_mtx);
}
return (error);
Expand Down
1 change: 1 addition & 0 deletions sys/net/bridgestp.c
Original file line number Diff line number Diff line change
Expand Up @@ -2017,6 +2017,7 @@ bstp_same_bridgeid(uint64_t id1, uint64_t id2)
void
bstp_reinit(struct bstp_state *bs)
{
INIT_VNET_NET(curvnet);
struct bstp_port *bp;
struct ifnet *ifp, *mif;
u_char *e_addr;
Expand Down
Loading

0 comments on commit 8797d4c

Please sign in to comment.