diff --git a/sys/netinet/dccp_usrreq.c b/sys/netinet/dccp_usrreq.c index dcc4b869c02..7844afb5030 100644 --- a/sys/netinet/dccp_usrreq.c +++ b/sys/netinet/dccp_usrreq.c @@ -443,8 +443,8 @@ dccp_input(struct mbuf *m, int off, int proto) #ifdef INET6 if (isipv6) { inp = sotoinpcb(so); - inp->inp_laddr6 = ip6->ip6_dst; - inp->inp_faddr6 = ip6->ip6_src; + in6p_laddr(inp) = ip6->ip6_dst; + in6p_faddr(inp) = ip6->ip6_src; inp->inp_lport = dh->dh_dport; inp->inp_fport = dh->dh_sport; in_pcbstate(inp, INP_CONNECTED); @@ -452,8 +452,8 @@ dccp_input(struct mbuf *m, int off, int proto) #endif { inp = sotoinpcb(so); - inp->inp_laddr = ip->ip_dst; - inp->inp_faddr = ip->ip_src; + in4p_laddr(inp) = ip->ip_dst; + in4p_faddr(inp) = ip->ip_src; inp->inp_lport = dh->dh_dport; inp->inp_fport = dh->dh_sport; } @@ -1353,12 +1353,12 @@ again: ip6 = mtod(m, struct ip6_hdr *); dh = (struct dccphdr *)(ip6 + 1); ip6->ip6_flow = (ip6->ip6_flow & ~IPV6_FLOWINFO_MASK) | - (inp->inp_flowinfo & IPV6_FLOWINFO_MASK); + (in6p_flowinfo(inp) & IPV6_FLOWINFO_MASK); ip6->ip6_vfc = (ip6->ip6_vfc & ~IPV6_VERSION_MASK) | (IPV6_VERSION & IPV6_VERSION_MASK); ip6->ip6_nxt = IPPROTO_DCCP; - ip6->ip6_src = inp->inp_laddr6; - ip6->ip6_dst = inp->inp_faddr6; + ip6->ip6_src = in6p_laddr(inp); + ip6->ip6_dst = in6p_faddr(inp); } else #endif { @@ -1366,8 +1366,8 @@ again: dh = (struct dccphdr *)(ip + 1); memset(ip, 0, sizeof(struct ip)); ip->ip_p = IPPROTO_DCCP; - ip->ip_src = inp->inp_laddr; - ip->ip_dst = inp->inp_faddr; + ip->ip_src = in4p_laddr(inp); + ip->ip_dst = in4p_faddr(inp); } dlh = (struct dccplhdr *)dh; @@ -1507,7 +1507,7 @@ again: if (isipv6) { DCCP_DEBUG((LOG_INFO, "Calling ip_output6, mbuf->m_len = %u, mbuf->m_pkthdr.len = %u\n", m->m_len, m->m_pkthdr.len)); - error = ip6_output(m, inp->inp_outputopts6, &inp->inp_route, + error = ip6_output(m, in6p_outputopts(inp), &inp->inp_route, (inp->inp_socket->so_options & SO_DONTROUTE), NULL, NULL, NULL); } else @@ -1705,7 +1705,7 @@ dccp_connect(struct socket *so, struct sockaddr *nam, struct lwp *l) return EINVAL; } INP_LOCK(inp); - if (inp->inp_faddr.s_addr != INADDR_ANY) { + if (in4p_faddr(inp).s_addr != INADDR_ANY) { INP_UNLOCK(inp); INP_INFO_WUNLOCK(&dccpbinfo); return EISCONN; @@ -1850,7 +1850,7 @@ dccp_disconnect(struct socket *so) return EINVAL; } INP_LOCK(inp); - if (inp->inp_faddr.s_addr == INADDR_ANY) { + if (in4p_faddr(inp).s_addr == INADDR_ANY) { INP_INFO_WUNLOCK(&dccpbinfo); INP_UNLOCK(inp); return ENOTCONN; @@ -2130,10 +2130,10 @@ dccp_newdccpcb(int family, void *aux) inp->inp_ppcb = dp; switch (family) { case PF_INET: - inp->inp_ip.ip_ttl = ip_defttl; + in4p_ip(inp).ip_ttl = ip_defttl; break; case PF_INET6: - inp->inp_ip6.ip6_hlim = in6_selecthlim_rt(inp); + in6p_ip6(inp).ip6_hlim = in6_selecthlim_rt(inp); break; } diff --git a/sys/netinet/in_pcb.c b/sys/netinet/in_pcb.c index 07537579f11..ba9ea2a480d 100644 --- a/sys/netinet/in_pcb.c +++ b/sys/netinet/in_pcb.c @@ -156,13 +156,16 @@ int anonportmax = IPPORT_ANONMAX; int lowportmin = IPPORT_RESERVEDMIN; int lowportmax = IPPORT_RESERVEDMAX; -static struct pool inpcb_pool; +static struct pool in4pcb_pool; +static struct pool in6pcb_pool; static int inpcb_poolinit(void) { - pool_init(&inpcb_pool, sizeof(struct inpcb), 0, 0, 0, "inpcbpl", NULL, + pool_init(&in4pcb_pool, sizeof(struct in4pcb), 0, 0, 0, "in4pcbpl", NULL, + IPL_NET); + pool_init(&in6pcb_pool, sizeof(struct in6pcb), 0, 0, 0, "in6pcbpl", NULL, IPL_NET); return 0; } @@ -194,30 +197,39 @@ in_pcballoc(struct socket *so, void *v) KASSERT(soaf(so) == AF_INET || soaf(so) == AF_INET6); - inp = pool_get(&inpcb_pool, PR_NOWAIT); + if (soaf(so) == AF_INET) + inp = pool_get(&in4pcb_pool, PR_NOWAIT|PR_ZERO); + else + inp = pool_get(&in6pcb_pool, PR_NOWAIT|PR_ZERO); if (inp == NULL) return (ENOBUFS); - memset(inp, 0, sizeof(*inp)); inp->inp_af = soaf(so); inp->inp_table = table; inp->inp_socket = so; - inp->inp_errormtu = -1; inp->inp_portalgo = PORTALGO_DEFAULT; inp->inp_bindportonsend = false; - inp->inp_prefsrcip.s_addr = INADDR_ANY; inp->inp_overudp_cb = NULL; inp->inp_overudp_arg = NULL; + + if (inp->inp_af == AF_INET) { + in4p_errormtu(inp) = -1; + in4p_prefsrcip(inp).s_addr = INADDR_ANY; + } #ifdef INET6 - inp->inp_hops6 = -1; /* use kernel default */ - inp->inp_icmp6filt = NULL; - if (inp->inp_af == AF_INET6 && ip6_v6only) - inp->inp_flags |= IN6P_IPV6_V6ONLY; + else { + in6p_hops6(inp) = -1; /* use kernel default */ + if (ip6_v6only) + inp->inp_flags |= IN6P_IPV6_V6ONLY; + } #endif #if defined(IPSEC) if (ipsec_enabled) { int error = ipsec_init_pcbpolicy(so, &inp->inp_sp); if (error != 0) { - pool_put(&inpcb_pool, inp); + if (inp->inp_af == AF_INET) + pool_put(&in4pcb_pool, inp); + else + pool_put(&in6pcb_pool, inp); return error; } inp->inp_sp->sp_inp = inp; @@ -325,7 +337,7 @@ in_pcbbind_addr(struct inpcb *inp, struct sockaddr_in *sin, kauth_cred_t cred) error = in_pcbbindableaddr(inp, sin, cred); if (error == 0) - inp->inp_laddr = sin->sin_addr; + in4p_laddr(inp) = sin->sin_addr; return error; } @@ -399,7 +411,7 @@ in_pcbbind_port(struct inpcb *inp, struct sockaddr_in *sin, kauth_cred_t cred) */ if (t && (!in_nullhost(sin->sin_addr) || - !in_nullhost(t->inp_laddr) || + !in_nullhost(in4p_laddr(t)) || (t->inp_socket->so_options & SO_REUSEPORT) == 0) && (so->so_uidinfo->ui_uid != t->inp_socket->so_uidinfo->ui_uid)) { return (EADDRINUSE); @@ -442,7 +454,7 @@ in_pcbbind(void *v, struct sockaddr_in *sin, struct lwp *l) if (inp->inp_af != AF_INET) return (EINVAL); - if (inp->inp_lport || !in_nullhost(inp->inp_laddr)) + if (inp->inp_lport || !in_nullhost(in4p_laddr(inp))) return (EINVAL); if (NULL != sin) { @@ -462,7 +474,7 @@ in_pcbbind(void *v, struct sockaddr_in *sin, struct lwp *l) /* Bind port. */ error = in_pcbbind_port(inp, sin, l->l_cred); if (error) { - inp->inp_laddr.s_addr = INADDR_ANY; + in4p_laddr(inp).s_addr = INADDR_ANY; return (error); } @@ -536,7 +548,7 @@ in_pcbconnect(void *v, struct sockaddr_in *sin, struct lwp *l) * chose a port number once, even if sending to multiple * destinations. */ - if (in_nullhost(inp->inp_laddr)) { + if (in_nullhost(in4p_laddr(inp))) { int xerror; struct in_ifaddr *ia, *_ia; int s; @@ -566,13 +578,13 @@ in_pcbconnect(void *v, struct sockaddr_in *sin, struct lwp *l) ia4_release(ia, &psref); curlwp_bindx(bound); } else - laddr = inp->inp_laddr; + laddr = in4p_laddr(inp); if (in_pcblookup_connect(inp->inp_table, sin->sin_addr, sin->sin_port, laddr, inp->inp_lport, &vestige) != NULL || vestige.valid) { return (EADDRINUSE); } - if (in_nullhost(inp->inp_laddr)) { + if (in_nullhost(in4p_laddr(inp))) { if (inp->inp_lport == 0) { error = in_pcbbind(inp, NULL, l); /* @@ -584,16 +596,16 @@ in_pcbconnect(void *v, struct sockaddr_in *sin, struct lwp *l) if (error != 0) return (error); } - inp->inp_laddr = laddr; + in4p_laddr(inp) = laddr; } - inp->inp_faddr = sin->sin_addr; + in4p_faddr(inp) = sin->sin_addr; inp->inp_fport = sin->sin_port; /* Late bind, if needed */ if (inp->inp_bindportonsend) { struct sockaddr_in lsin = *((const struct sockaddr_in *) inp->inp_socket->so_proto->pr_domain->dom_sa_any); - lsin.sin_addr = inp->inp_laddr; + lsin.sin_addr = in4p_laddr(inp); lsin.sin_port = 0; if ((error = in_pcbbind_port(inp, &lsin, l->l_cred)) != 0) @@ -616,7 +628,7 @@ in_pcbdisconnect(void *v) if (inp->inp_af != AF_INET) return; - inp->inp_faddr = zeroin_addr; + in4p_faddr(inp) = zeroin_addr; inp->inp_fport = 0; in_pcbstate(inp, INP_BOUND); #if defined(IPSEC) @@ -651,16 +663,21 @@ in_pcbdetach(void *v) if (inp->inp_options) { m_free(inp->inp_options); } - if (inp->inp_outputopts6 != NULL) { - ip6_clearpktopts(inp->inp_outputopts6, -1); - free(inp->inp_outputopts6, M_IP6OPT); - } rtcache_free(&inp->inp_route); - ip6_freemoptions(inp->inp_moptions6); ip_freemoptions(inp->inp_moptions); + if (inp->inp_af == AF_INET6) { + if (in6p_outputopts(inp) != NULL) { + ip6_clearpktopts(in6p_outputopts(inp), -1); + free(in6p_outputopts(inp), M_IP6OPT); + } + ip6_freemoptions(in6p_moptions(inp)); + } sofree(so); /* drops the socket's lock */ - pool_put(&inpcb_pool, inp); + if (inp->inp_af == AF_INET) + pool_put(&in4pcb_pool, inp); + else + pool_put(&in6pcb_pool, inp); mutex_enter(softnet_lock); /* reacquire the softnet_lock */ } @@ -671,7 +688,7 @@ in_setsockaddr(struct inpcb *inp, struct sockaddr_in *sin) if (inp->inp_af != AF_INET) return; - sockaddr_in_init(sin, &inp->inp_laddr, inp->inp_lport); + sockaddr_in_init(sin, &in4p_laddr(inp), inp->inp_lport); } void @@ -681,7 +698,7 @@ in_setpeeraddr(struct inpcb *inp, struct sockaddr_in *sin) if (inp->inp_af != AF_INET) return; - sockaddr_in_init(sin, &inp->inp_faddr, inp->inp_fport); + sockaddr_in_init(sin, &in4p_faddr(inp), inp->inp_fport); } /* @@ -714,10 +731,10 @@ in_pcbnotify(struct inpcbtable *table, struct in_addr faddr, u_int fport_arg, if (inp->inp_af != AF_INET) continue; - if (in_hosteq(inp->inp_faddr, faddr) && + if (in_hosteq(in4p_faddr(inp), faddr) && inp->inp_fport == fport && inp->inp_lport == lport && - in_hosteq(inp->inp_laddr, laddr)) { + in_hosteq(in4p_laddr(inp), laddr)) { (*notify)(inp, errno); nmatch++; } @@ -737,7 +754,7 @@ in_pcbnotifyall(struct inpcbtable *table, struct in_addr faddr, int errno, TAILQ_FOREACH(inp, &table->inpt_queue, inp_queue) { if (inp->inp_af != AF_INET) continue; - if (in_hosteq(inp->inp_faddr, faddr)) + if (in_hosteq(in4p_faddr(inp), faddr)) (*notify)(inp, errno); } } @@ -907,16 +924,16 @@ in_pcblookup_port(struct inpcbtable *table, struct in_addr laddr, * A A match */ wildcard = 0; - if (!in_nullhost(inp->inp_faddr)) + if (!in_nullhost(in4p_faddr(inp))) wildcard++; - if (in_nullhost(inp->inp_laddr)) { + if (in_nullhost(in4p_laddr(inp))) { if (!in_nullhost(laddr)) wildcard++; } else { if (in_nullhost(laddr)) wildcard++; else { - if (!in_hosteq(inp->inp_laddr, laddr)) + if (!in_hosteq(in4p_laddr(inp), laddr)) continue; } } @@ -1002,10 +1019,10 @@ in_pcblookup_connect(struct inpcbtable *table, if (inp->inp_af != AF_INET) continue; - if (in_hosteq(inp->inp_faddr, faddr) && + if (in_hosteq(in4p_faddr(inp), faddr) && inp->inp_fport == fport && inp->inp_lport == lport && - in_hosteq(inp->inp_laddr, laddr)) + in_hosteq(in4p_laddr(inp), laddr)) goto out; } if (vp && table->vestige) { @@ -1046,7 +1063,7 @@ in_pcblookup_bind(struct inpcbtable *table, continue; if (inp->inp_lport == lport && - in_hosteq(inp->inp_laddr, laddr)) + in_hosteq(in4p_laddr(inp), laddr)) goto out; } head = INPCBHASH_BIND(table, zeroin_addr, lport); @@ -1055,7 +1072,7 @@ in_pcblookup_bind(struct inpcbtable *table, continue; if (inp->inp_lport == lport && - in_hosteq(inp->inp_laddr, zeroin_addr)) + in_hosteq(in4p_laddr(inp), zeroin_addr)) goto out; } #ifdef DIAGNOSTIC @@ -1090,13 +1107,13 @@ in_pcbstate(struct inpcb *inp, int state) switch (state) { case INP_BOUND: LIST_INSERT_HEAD(INPCBHASH_BIND(inp->inp_table, - inp->inp_laddr, inp->inp_lport), inp, + in4p_laddr(inp), inp->inp_lport), inp, inp_hash); break; case INP_CONNECTED: LIST_INSERT_HEAD(INPCBHASH_CONNECT(inp->inp_table, - inp->inp_faddr, inp->inp_fport, - inp->inp_laddr, inp->inp_lport), inp, + in4p_faddr(inp), inp->inp_fport, + in4p_laddr(inp), inp->inp_lport), inp, inp_hash); break; } @@ -1120,7 +1137,7 @@ in_pcbrtentry(struct inpcb *inp) ro = &inp->inp_route; - sockaddr_in_init(&u.dst4, &inp->inp_faddr, 0); + sockaddr_in_init(&u.dst4, &in4p_faddr(inp), 0); return rtcache_lookup(ro, &u.dst); } diff --git a/sys/netinet/in_pcb.h b/sys/netinet/in_pcb.h index b83e943c2dd..3f08cf541fd 100644 --- a/sys/netinet/in_pcb.h +++ b/sys/netinet/in_pcb.h @@ -78,14 +78,6 @@ struct ip_moptions; struct mbuf; struct icmp6_filter; -union inpaddru { - struct in6_addr iau_addr6; - struct { - uint8_t pad[12]; - struct in_addr inaddr; /* easier transition */ - } iau_a4u; -}; - /* * Common structure pcb for internet protocol implementation. * Here are stored pointers to local and foreign host table @@ -107,51 +99,61 @@ struct inpcb { int inp_portalgo; struct socket *inp_socket; /* back pointer to socket */ struct inpcbtable *inp_table; - union inpaddru inp_faddru; /* Foreign address. */ - union inpaddru inp_laddru; /* Local address. */ -#define inp_faddr inp_faddru.iau_a4u.inaddr -#define inp_faddr6 inp_faddru.iau_addr6 -#define inp_laddr inp_laddru.iau_a4u.inaddr -#define inp_laddr6 inp_laddru.iau_addr6 struct inpcbpolicy *inp_sp; /* security policy */ struct route inp_route; /* placeholder for routing entry */ u_int16_t inp_fport; /* foreign port */ u_int16_t inp_lport; /* local port */ int inp_flags; /* generic IP/datagram flags */ - union { /* header prototype. */ - struct ip inp_ip; - struct ip6_hdr inp_ip6; - }; -#define inp_flowinfo inp_ip6.ip6_flow struct mbuf *inp_options; /* IP options */ bool inp_bindportonsend; - /* We still need both for IPv6 due to v4-mapped addresses */ + /* We still need it for IPv6 due to v4-mapped addresses */ struct ip_moptions *inp_moptions; /* IPv4 multicast options */ - struct ip6_moptions *inp_moptions6; /* IPv6 multicast options */ - - union { - /* IPv4 only stuffs */ - struct { - int inp_errormtu; /* MTU of last xmit status = EMSGSIZE */ - uint8_t inp_ip_minttl; - struct in_addr inp_prefsrcip; /* preferred src IP when wild */ - }; - /* IPv6 only stuffs */ - struct { - int inp_hops6; /* default IPv6 hop limit */ - int inp_cksum6; /* IPV6_CHECKSUM setsockopt */ - struct icmp6_filter *inp_icmp6filt; - struct ip6_pktopts *inp_outputopts6; /* IP6 options for outgoing packets */ - }; - }; pcb_overudp_cb_t inp_overudp_cb; void *inp_overudp_arg; }; -#define inp_faddr inp_ip.ip_dst -#define inp_laddr inp_ip.ip_src +struct in4pcb { + struct inpcb in4p_pcb; + struct ip in4p_ip; + int in4p_errormtu; /* MTU of last xmit status = EMSGSIZE */ + uint8_t in4p_ip_minttl; + struct in_addr in4p_prefsrcip; /* preferred src IP when wild */ +}; + +#define in4p_faddr(inpcb) (((struct in4pcb *)(inpcb))->in4p_ip.ip_dst) +#define in4p_laddr(inpcb) (((struct in4pcb *)(inpcb))->in4p_ip.ip_src) +#define const_in4p_faddr(inpcb) (((const struct in4pcb *)(inpcb))->in4p_ip.ip_dst) +#define const_in4p_laddr(inpcb) (((const struct in4pcb *)(inpcb))->in4p_ip.ip_src) +#define in4p_ip(inpcb) (((struct in4pcb *)(inpcb))->in4p_ip) +#define in4p_errormtu(inpcb) (((struct in4pcb *)(inpcb))->in4p_errormtu) +#define in4p_ip_minttl(inpcb) (((struct in4pcb *)(inpcb))->in4p_ip_minttl) +#define in4p_prefsrcip(inpcb) (((struct in4pcb *)(inpcb))->in4p_prefsrcip) + +struct in6pcb { + struct inpcb in6p_pcb; + struct ip6_hdr in6p_ip6; + int in6p_hops; /* default IPv6 hop limit */ + int in6p_cksum; /* IPV6_CHECKSUM setsockopt */ + struct icmp6_filter *in6p_icmp6filt; + struct ip6_pktopts *in6p_outputopts; /* IP6 options for outgoing packets */ + struct ip6_moptions *in6p_moptions; /* IPv6 multicast options */ +}; + +#define in6p_faddr(inpcb) (((struct in6pcb *)(inpcb))->in6p_ip6.ip6_dst) +#define in6p_laddr(inpcb) (((struct in6pcb *)(inpcb))->in6p_ip6.ip6_src) +#define const_in6p_faddr(inpcb) (((const struct in6pcb *)(inpcb))->in6p_ip6.ip6_dst) +#define const_in6p_laddr(inpcb) (((const struct in6pcb *)(inpcb))->in6p_ip6.ip6_src) +#define in6p_ip6(inpcb) (((struct in6pcb *)(inpcb))->in6p_ip6) +#define in6p_flowinfo(inpcb) (((struct in6pcb *)(inpcb))->in6p_ip6.ip6_flow) +#define const_in6p_flowinfo(inpcb) (((const struct in6pcb *)(inpcb))->in6p_ip6.ip6_flow) +#define in6p_hops6(inpcb) (((struct in6pcb *)(inpcb))->in6p_hops) +#define in6p_cksum(inpcb) (((struct in6pcb *)(inpcb))->in6p_cksum) +#define in6p_icmp6filt(inpcb) (((struct in6pcb *)(inpcb))->in6p_icmp6filt) +#define in6p_outputopts(inpcb) (((struct in6pcb *)(inpcb))->in6p_outputopts) +#define in6p_moptions(inpcb) (((struct in6pcb *)(inpcb))->in6p_moptions) + LIST_HEAD(inpcbhead, inpcb); /* flags in inp_flags: */ diff --git a/sys/netinet/ip_output.c b/sys/netinet/ip_output.c index 3e04d22aeea..fa1b902d186 100644 --- a/sys/netinet/ip_output.c +++ b/sys/netinet/ip_output.c @@ -763,7 +763,7 @@ fragment: if (ntohs(ip->ip_off) & IP_DF) { if (flags & IP_RETURNMTU) { KASSERT(inp != NULL); - inp->inp_errormtu = mtu; + in4p_errormtu(inp) = mtu; } error = EMSGSIZE; IP_STATINC(IP_STAT_CANTFRAG); @@ -1088,7 +1088,7 @@ int ip_ctloutput(int op, struct socket *so, struct sockopt *sopt) { struct inpcb *inp = sotoinpcb(so); - struct ip *ip = &inp->inp_ip; + struct ip *ip = &in4p_ip(inp); int inpflags = inp->inp_flags; int optval = 0, error = 0; struct in_pktinfo pktinfo; @@ -1136,7 +1136,7 @@ ip_ctloutput(int op, struct socket *so, struct sockopt *sopt) case IP_MINTTL: if (optval > 0 && optval <= MAXTTL) - inp->inp_ip_minttl = optval; + in4p_ip_minttl(inp) = optval; else error = EINVAL; break; @@ -1193,7 +1193,7 @@ ip_ctloutput(int op, struct socket *so, struct sockopt *sopt) break; if (pktinfo.ipi_ifindex == 0) { - inp->inp_prefsrcip = pktinfo.ipi_addr; + in4p_prefsrcip(inp) = pktinfo.ipi_addr; break; } @@ -1216,7 +1216,7 @@ ip_ctloutput(int op, struct socket *so, struct sockopt *sopt) error = EADDRNOTAVAIL; break; } - inp->inp_prefsrcip = IA_SIN(ia)->sin_addr; + in4p_prefsrcip(inp) = IA_SIN(ia)->sin_addr; pserialize_read_exit(s); break; break; @@ -1315,11 +1315,11 @@ ip_ctloutput(int op, struct socket *so, struct sockopt *sopt) break; case IP_MINTTL: - optval = inp->inp_ip_minttl; + optval = in4p_ip_minttl(inp); break; case IP_ERRORMTU: - optval = inp->inp_errormtu; + optval = in4p_errormtu(inp); break; #define OPTBIT(bit) (inpflags & bit ? 1 : 0) @@ -1365,7 +1365,7 @@ ip_ctloutput(int op, struct socket *so, struct sockopt *sopt) case sizeof(struct in_pktinfo): /* Solaris compatibility */ pktinfo.ipi_ifindex = 0; - pktinfo.ipi_addr = inp->inp_prefsrcip; + pktinfo.ipi_addr = in4p_prefsrcip(inp); error = sockopt_set(sopt, &pktinfo, sizeof(pktinfo)); break; @@ -1503,8 +1503,8 @@ ip_setpktopts(struct mbuf *control, struct ip_pktopts *pktopts, int *flags, pktopts->ippo_imo = inp->inp_moptions; - struct in_addr *ia = in_nullhost(inp->inp_prefsrcip) ? &inp->inp_laddr : - &inp->inp_prefsrcip; + struct in_addr *ia = in_nullhost(in4p_prefsrcip(inp)) ? &in4p_laddr(inp) : + &in4p_prefsrcip(inp); sockaddr_in_init(&pktopts->ippo_laddr, ia, 0); if (control == NULL) diff --git a/sys/netinet/portalgo.c b/sys/netinet/portalgo.c index 8fa34859a55..89fab9350de 100644 --- a/sys/netinet/portalgo.c +++ b/sys/netinet/portalgo.c @@ -260,7 +260,7 @@ check_suitable_port(uint16_t port, struct inpcb *inp, kauth_cred_t cred) if (__BITMAP_ISSET(port, &inet4_reserve)) return false; - sin.sin_addr = inp->inp_laddr; + sin.sin_addr = in4p_laddr(inp); pcb = in_pcblookup_port(table, sin.sin_addr, htons(port), 1, &vestigial); @@ -304,7 +304,7 @@ check_suitable_port(uint16_t port, struct inpcb *inp, kauth_cred_t cred) if (__BITMAP_ISSET(port, &inet6_reserve)) return false; - sin6.sin6_addr = inp->inp_laddr6; + sin6.sin6_addr = in6p_laddr(inp); so = inp->inp_socket; /* XXX: this is redundant when called from in6_pcbbind */ @@ -521,10 +521,10 @@ Fhash(const struct inpcb *inp) switch (inp->inp_af) { #ifdef INET case AF_INET: { - MD5Update(&f_ctx, (const u_char *)&inp->inp_laddr, - sizeof(inp->inp_laddr)); - MD5Update(&f_ctx, (const u_char *)&inp->inp_faddr, - sizeof(inp->inp_faddr)); + MD5Update(&f_ctx, (const u_char *)&const_in4p_laddr(inp), + sizeof(const_in4p_laddr(inp))); + MD5Update(&f_ctx, (const u_char *)&const_in4p_faddr(inp), + sizeof(const_in4p_faddr(inp))); MD5Update(&f_ctx, (const u_char *)&inp->inp_fport, sizeof(inp->inp_fport)); break; @@ -532,10 +532,10 @@ Fhash(const struct inpcb *inp) #endif #ifdef INET6 case AF_INET6: { - MD5Update(&f_ctx, (const u_char *)&inp->inp_laddr6, - sizeof(inp->inp_laddr6)); - MD5Update(&f_ctx, (const u_char *)&inp->inp_faddr6, - sizeof(inp->inp_faddr6)); + MD5Update(&f_ctx, (const u_char *)&const_in6p_laddr(inp), + sizeof(const_in6p_laddr(inp))); + MD5Update(&f_ctx, (const u_char *)&const_in6p_faddr(inp), + sizeof(const_in6p_faddr(inp))); MD5Update(&f_ctx, (const u_char *)&inp->inp_fport, sizeof(inp->inp_fport)); break; @@ -565,7 +565,7 @@ iscompletetuple(struct inpcb *inp) switch (inp->inp_af) { #ifdef INET case AF_INET: { - if (inp->inp_fport == 0 || in_nullhost(inp->inp_faddr)) { + if (inp->inp_fport == 0 || in_nullhost(in4p_faddr(inp))) { DPRINTF("%s fport or faddr missing, delaying port " "to connect/send\n", __func__); inp->inp_bindportonsend = true; @@ -578,8 +578,8 @@ iscompletetuple(struct inpcb *inp) #endif #ifdef INET6 case AF_INET6: { - if (inp->inp_fport == 0 || memcmp(&inp->inp_faddr6, - &in6addr_any, sizeof(inp->inp_faddr6)) == 0) { + if (inp->inp_fport == 0 || memcmp(&in6p_faddr(inp), + &in6addr_any, sizeof(in6p_faddr(inp))) == 0) { DPRINTF("%s fport or faddr missing, delaying port " "to connect/send\n", __func__); inp->inp_bindportonsend = true; @@ -783,9 +783,9 @@ portalgo_randport(uint16_t *port, struct inpcb *inp, kauth_cred_t cred) #ifdef INET case AF_INET: { char buf[INET_ADDRSTRLEN]; - DPRINTF("local addr: %s\n", IN_PRINT(buf, &inp->inp_laddr)); + DPRINTF("local addr: %s\n", IN_PRINT(buf, &in4p_laddr(inp))); DPRINTF("local port: %d\n", inp->inp_lport); - DPRINTF("foreign addr: %s\n", IN_PRINT(buf, &inp->inp_faddr)); + DPRINTF("foreign addr: %s\n", IN_PRINT(buf, &in4p_faddr(inp))); DPRINTF("foreign port: %d\n", inp->inp_fport); break; } @@ -793,10 +793,10 @@ portalgo_randport(uint16_t *port, struct inpcb *inp, kauth_cred_t cred) #ifdef INET6 case AF_INET6: { char buf[INET6_ADDRSTRLEN]; - DPRINTF("local addr: %s\n", IN6_PRINT(buf, &inp->inp_laddr6)); + DPRINTF("local addr: %s\n", IN6_PRINT(buf, &in6p_laddr(inp))); DPRINTF("local port: %d\n", inp->inp_lport); DPRINTF("foreign addr: %s\n", IN6_PRINT(buf, - &inp->inp_laddr6)); + &in6p_laddr(inp))); DPRINTF("foreign port: %d\n", inp->inp_fport); break; } diff --git a/sys/netinet/raw_ip.c b/sys/netinet/raw_ip.c index 4f608e13b92..1d0bba998af 100644 --- a/sys/netinet/raw_ip.c +++ b/sys/netinet/raw_ip.c @@ -185,13 +185,13 @@ rip_input(struct mbuf *m, int off, int proto) TAILQ_FOREACH(inp, &rawcbtable.inpt_queue, inp_queue) { if (inp->inp_af != AF_INET) continue; - if (inp->inp_ip.ip_p && inp->inp_ip.ip_p != proto) + if (in4p_ip(inp).ip_p && in4p_ip(inp).ip_p != proto) continue; - if (!in_nullhost(inp->inp_laddr) && - !in_hosteq(inp->inp_laddr, ip->ip_dst)) + if (!in_nullhost(in4p_laddr(inp)) && + !in_hosteq(in4p_laddr(inp), ip->ip_dst)) continue; - if (!in_nullhost(inp->inp_faddr) && - !in_hosteq(inp->inp_faddr, ip->ip_src)) + if (!in_nullhost(in4p_faddr(inp)) && + !in_hosteq(in4p_faddr(inp), ip->ip_src)) continue; if (last == NULL) { @@ -246,10 +246,10 @@ rip_pcbnotify(struct inpcbtable *table, TAILQ_FOREACH(inp, &table->inpt_queue, inp_queue) { if (inp->inp_af != AF_INET) continue; - if (inp->inp_ip.ip_p && inp->inp_ip.ip_p != proto) + if (in4p_ip(inp).ip_p && in4p_ip(inp).ip_p != proto) continue; - if (in_hosteq(inp->inp_faddr, faddr) && - in_hosteq(inp->inp_laddr, laddr)) { + if (in_hosteq(in4p_faddr(inp), faddr) && + in_hosteq(in4p_laddr(inp), laddr)) { (*notify)(inp, errno); nmatch++; } @@ -335,10 +335,10 @@ rip_output(struct mbuf *m, struct inpcb *inp, struct mbuf *control, ip = mtod(m, struct ip *); ip->ip_tos = 0; ip->ip_off = htons(0); - ip->ip_p = inp->inp_ip.ip_p; + ip->ip_p = in4p_ip(inp).ip_p; ip->ip_len = htons(m->m_pkthdr.len); ip->ip_src = pktopts.ippo_laddr.sin_addr; - ip->ip_dst = inp->inp_faddr; + ip->ip_dst = in4p_faddr(inp); ip->ip_ttl = MAXTTL; opts = inp->inp_options; } else { @@ -498,7 +498,7 @@ rip_connect_pcb(struct inpcb *inp, struct sockaddr_in *addr) return (EAFNOSUPPORT); if (addr->sin_len != sizeof(*addr)) return EINVAL; - inp->inp_faddr = addr->sin_addr; + in4p_faddr(inp) = addr->sin_addr; return (0); } @@ -506,7 +506,7 @@ static void rip_disconnect1(struct inpcb *inp) { - inp->inp_faddr = zeroin_addr; + in4p_faddr(inp) = zeroin_addr; } static int @@ -530,7 +530,7 @@ rip_attach(struct socket *so, int proto) return error; } inp = sotoinpcb(so); - inp->inp_ip.ip_p = proto; + in4p_ip(inp).ip_p = proto; KASSERT(solocked(so)); return 0; @@ -605,7 +605,7 @@ rip_bind(struct socket *so, struct sockaddr *nam, struct lwp *l) } pserialize_read_exit(ss); - inp->inp_laddr = addr->sin_addr; + in4p_laddr(inp) = addr->sin_addr; release: splx(s); diff --git a/sys/netinet/sctp_output.c b/sys/netinet/sctp_output.c index 042722d2683..4851feb446f 100644 --- a/sys/netinet/sctp_output.c +++ b/sys/netinet/sctp_output.c @@ -2137,11 +2137,11 @@ sctp_lowlevel_chunk_output(struct sctp_inpcb *inp, if (stcb) { if ((stcb->asoc.ecn_allowed) && ecn_ok) { /* Enable ECN */ - ip->ip_tos = (u_char)((inp->ip_inp.inp.inp_ip.ip_tos & 0x000000fc) | + ip->ip_tos = (u_char)((in4p_ip(&inp->ip_inp.inp).ip_tos & 0x000000fc) | sctp_get_ect(stcb, chk)); } else { /* No ECN */ - ip->ip_tos = inp->ip_inp.inp.inp_ip.ip_tos; + ip->ip_tos = in4p_ip(&inp->ip_inp.inp).ip_tos; } } else { /* no association at all */ @@ -2299,10 +2299,10 @@ sctp_lowlevel_chunk_output(struct sctp_inpcb *inp, * We assume here that inp_flow is in host byte order within * the TCB! */ - flowBottom = ((struct in6pcb *)inp)->in6p_flowinfo & 0x0000ffff; - flowTop = ((((struct in6pcb *)inp)->in6p_flowinfo & 0x000f0000) >> 16); + flowBottom = in6p_flowinfo(inp) & 0x0000ffff; + flowTop = ((in6p_flowinfo(inp) & 0x000f0000) >> 16); - tosTop = (((((struct in6pcb *)inp)->in6p_flowinfo & 0xf0) >> 4) | IPV6_VERSION); + tosTop = (((in6p_flowinfo(inp) & 0xf0) >> 4) | IPV6_VERSION); /* protect *sin6 from overwrite */ memcpy(&tmp, to, sizeof(struct sockaddr_in6)); @@ -2331,14 +2331,14 @@ sctp_lowlevel_chunk_output(struct sctp_inpcb *inp, if (stcb != NULL) { if ((stcb->asoc.ecn_allowed) && ecn_ok) { /* Enable ECN */ - tosBottom = (((((struct in6pcb *)inp)->in6p_flowinfo & 0x0c) | sctp_get_ect(stcb, chk)) << 4); + tosBottom = (((in6p_flowinfo(inp) & 0x0c) | sctp_get_ect(stcb, chk)) << 4); } else { /* No ECN */ - tosBottom = ((((struct in6pcb *)inp)->in6p_flowinfo & 0x0c) << 4); + tosBottom = ((in6p_flowinfo(inp) & 0x0c) << 4); } } else { /* we could get no asoc if it is a O-O-T-B packet */ - tosBottom = ((((struct in6pcb *)inp)->in6p_flowinfo & 0x0c) << 4); + tosBottom = ((in6p_flowinfo(inp) & 0x0c) << 4); } ip6h->ip6_flow = htonl(((tosTop << 24) | ((tosBottom|flowTop) << 16) | flowBottom)); ip6h->ip6_nxt = IPPROTO_SCTP; @@ -2416,7 +2416,7 @@ sctp_lowlevel_chunk_output(struct sctp_inpcb *inp, * We set the hop limit now since there is a good chance that * our ro pointer is now filled */ - ip6h->ip6_hlim = in6_selecthlim((struct in6pcb *)&inp->ip_inp.inp, + ip6h->ip6_hlim = in6_selecthlim(&inp->ip_inp.inp, (ro ? (rt ? (rt->rt_ifp) : (NULL)) : (NULL))); @@ -2447,7 +2447,7 @@ sctp_lowlevel_chunk_output(struct sctp_inpcb *inp, ro, o_flgs, ((struct in6pcb *)inp)->in6p_moptions, - (struct in6pcb *)inp, + (struct inpcb *)inp, &ifp); if (net) { /* for link local this must be done */ diff --git a/sys/netinet/sctp_pcb.h b/sys/netinet/sctp_pcb.h index 0880bcb20a2..7dc1308678e 100644 --- a/sys/netinet/sctp_pcb.h +++ b/sys/netinet/sctp_pcb.h @@ -288,7 +288,7 @@ struct sctp_inpcb { */ union { struct inpcb inp; - char align[(sizeof(struct inpcb) + SCTP_ALIGNM1) & + char align[(sizeof(struct in6pcb) + SCTP_ALIGNM1) & ~SCTP_ALIGNM1]; } ip_inp; LIST_ENTRY(sctp_inpcb) sctp_list; /* lists all endpoints */ @@ -753,32 +753,14 @@ void in6_sin6_2_sin (struct sockaddr_in *, struct sockaddr_in6 *sin6); #ifdef __NetBSD__ -#ifndef in6pcb -#define in6pcb inpcb -#endif #ifndef sotoin6pcb -#define sotoin6pcb sotoinpcb +#define sotoin6pcb(so) ((struct in6pcb *)((so)->so_pcb)) #endif #ifndef in6p_flags -#define in6p_flags inp_flags +#define in6p_flags in6p_pcb.inp_flags #endif #ifndef in6p_af -#define in6p_af inp_af -#endif -#ifndef in6p_cksum -#define in6p_cksum inp_cksum6 -#endif -#ifndef in6p_hops -#define in6p_hops inp_hops6 -#endif -#ifndef in6p_flowinfo -#define in6p_flowinfo inp_flowinfo -#endif -#ifndef in6p_outputopts -#define in6p_outputopts inp_outputopts6 -#endif -#ifndef in6p_moptions -#define in6p_moptions inp_moptions6 +#define in6p_af in6p_pcb.inp_af #endif #ifndef inpcb_hdr #define inpcb_hdr inpcb diff --git a/sys/netinet/tcp_input.c b/sys/netinet/tcp_input.c index 6113b9d4e2e..0f759d8b81d 100644 --- a/sys/netinet/tcp_input.c +++ b/sys/netinet/tcp_input.c @@ -1453,7 +1453,7 @@ findpcb: so = NULL; if (inp) { /* Check the minimum TTL for socket. */ - if (inp->inp_af == AF_INET && ip->ip_ttl < inp->inp_ip_minttl) + if (inp->inp_af == AF_INET && ip->ip_ttl < in4p_ip_minttl(inp)) goto drop; tp = intotcpcb(inp); @@ -1481,7 +1481,7 @@ findpcb: #ifdef INET6 /* save packet options if user wanted */ - if (inp && (inp->inp_flags & IN6P_CONTROLOPTS)) { + if (inp->inp_af == AF_INET6 && (inp->inp_flags & IN6P_CONTROLOPTS)) { if (inp->inp_options) { m_freem(inp->inp_options); inp->inp_options = NULL; @@ -2088,10 +2088,10 @@ after_listen: tp->snd_cwnd = tp->t_peermss; else { int ss = tcp_init_win; - if (inp->inp_af == AF_INET && in_localaddr(inp->inp_faddr)) + if (inp->inp_af == AF_INET && in_localaddr(in4p_faddr(inp))) ss = tcp_init_win_local; #ifdef INET6 - else if (inp->inp_af == AF_INET6 && in6_localaddr(&inp->inp_faddr6)) + else if (inp->inp_af == AF_INET6 && in6_localaddr(&in6p_faddr(inp))) ss = tcp_init_win_local; #endif tp->snd_cwnd = TCP_INITIAL_WINDOW(ss, tp->t_peermss); diff --git a/sys/netinet/tcp_output.c b/sys/netinet/tcp_output.c index b5dbc2294d7..5d2289729e2 100644 --- a/sys/netinet/tcp_output.c +++ b/sys/netinet/tcp_output.c @@ -276,16 +276,16 @@ tcp_segsize(struct tcpcb *tp, int *txsegsizep, int *rxsegsizep, #endif } else if (ifp->if_flags & IFF_LOOPBACK) size = ifp->if_mtu - hdrlen; - else if (inp && tp->t_mtudisc) + else if (inp->inp_af == AF_INET && tp->t_mtudisc) size = ifp->if_mtu - hdrlen; - else if (inp && in_localaddr(inp->inp_faddr)) + else if (inp->inp_af == AF_INET && in_localaddr(in4p_faddr(inp))) size = ifp->if_mtu - hdrlen; #ifdef INET6 else if (inp->inp_af == AF_INET6) { - if (IN6_IS_ADDR_V4MAPPED(&inp->inp_faddr6)) { + if (IN6_IS_ADDR_V4MAPPED(&in6p_faddr(inp))) { /* mapped addr case */ struct in_addr d; - memcpy(&d, &inp->inp_faddr6.s6_addr32[3], sizeof(d)); + memcpy(&d, &in6p_faddr(inp).s6_addr32[3], sizeof(d)); if (tp->t_mtudisc || in_localaddr(d)) size = ifp->if_mtu - hdrlen; } else { @@ -619,11 +619,11 @@ tcp_output(struct tcpcb *tp) */ int ss = tcp_init_win; if (tp->t_inpcb->inp_af == AF_INET && - in_localaddr(tp->t_inpcb->inp_faddr)) + in_localaddr(in4p_faddr(tp->t_inpcb))) ss = tcp_init_win_local; #ifdef INET6 else if (tp->t_inpcb->inp_af == AF_INET6 && - in6_localaddr(&tp->t_inpcb->inp_faddr6)) + in6_localaddr(&in6p_faddr(tp->t_inpcb))) ss = tcp_init_win_local; #endif tp->snd_cwnd = uimin(tp->snd_cwnd, @@ -1541,8 +1541,8 @@ timer: ip->ip_len = htons(m->m_pkthdr.len); packetlen = m->m_pkthdr.len; if (tp->t_inpcb->inp_af == AF_INET) { - ip->ip_ttl = tp->t_inpcb->inp_ip.ip_ttl; - ip->ip_tos = tp->t_inpcb->inp_ip.ip_tos | ecn_tos; + ip->ip_ttl = in4p_ip(tp->t_inpcb).ip_ttl; + ip->ip_tos = in4p_ip(tp->t_inpcb).ip_tos | ecn_tos; } #ifdef INET6 else if (tp->t_inpcb->inp_af == AF_INET6) { @@ -1579,7 +1579,7 @@ timer: { struct mbuf *opts; - if (tp->t_inpcb && tp->t_family == AF_INET) + if (tp->t_inpcb->inp_af == AF_INET) opts = tp->t_inpcb->inp_options; else opts = NULL; @@ -1593,8 +1593,8 @@ timer: { struct ip6_pktopts *opts; - if (tp->t_inpcb && tp->t_family == AF_INET6) - opts = tp->t_inpcb->inp_outputopts6; + if (tp->t_inpcb->inp_af == AF_INET6) + opts = in6p_outputopts(tp->t_inpcb); else opts = NULL; error = ip6_output(m, opts, ro, so->so_options & SO_DONTROUTE, diff --git a/sys/netinet/tcp_subr.c b/sys/netinet/tcp_subr.c index b2add6727d3..c26547bf6b1 100644 --- a/sys/netinet/tcp_subr.c +++ b/sys/netinet/tcp_subr.c @@ -460,8 +460,8 @@ tcp_template(struct tcpcb *tp) #ifdef INET6 if (inp->inp_af == AF_INET6) { /* mapped addr case */ - if (IN6_IS_ADDR_V4MAPPED(&inp->inp_laddr6) - && IN6_IS_ADDR_V4MAPPED(&inp->inp_faddr6)) + if (IN6_IS_ADDR_V4MAPPED(&in6p_laddr(inp)) + && IN6_IS_ADDR_V4MAPPED(&in6p_faddr(inp))) break; } #endif @@ -516,15 +516,15 @@ tcp_template(struct tcpcb *tp) ipov->ih_pr = IPPROTO_TCP; ipov->ih_len = htons(sizeof(struct tcphdr)); if (inp->inp_af == AF_INET) { - ipov->ih_src = inp->inp_laddr; - ipov->ih_dst = inp->inp_faddr; + ipov->ih_src = in4p_laddr(inp); + ipov->ih_dst = in4p_faddr(inp); } #ifdef INET6 else if (inp->inp_af == AF_INET6) { /* mapped addr case */ - bcopy(&inp->inp_laddr6.s6_addr32[3], &ipov->ih_src, + bcopy(&in6p_laddr(inp).s6_addr32[3], &ipov->ih_src, sizeof(ipov->ih_src)); - bcopy(&inp->inp_faddr6.s6_addr32[3], &ipov->ih_dst, + bcopy(&in6p_faddr(inp).s6_addr32[3], &ipov->ih_dst, sizeof(ipov->ih_dst)); } #endif @@ -549,9 +549,9 @@ tcp_template(struct tcpcb *tp) ip6 = mtod(m, struct ip6_hdr *); ip6->ip6_nxt = IPPROTO_TCP; ip6->ip6_plen = htons(sizeof(struct tcphdr)); - ip6->ip6_src = inp->inp_laddr6; - ip6->ip6_dst = inp->inp_faddr6; - ip6->ip6_flow = inp->inp_flowinfo & IPV6_FLOWINFO_MASK; + ip6->ip6_src = in6p_laddr(inp); + ip6->ip6_dst = in6p_faddr(inp); + ip6->ip6_flow = in6p_flowinfo(inp) & IPV6_FLOWINFO_MASK; if (ip6_auto_flowlabel) { ip6->ip6_flow &= ~IPV6_FLOWLABEL_MASK; ip6->ip6_flow |= @@ -567,8 +567,8 @@ tcp_template(struct tcpcb *tp) * checksum right before the packet is sent off onto * the wire. */ - n->th_sum = in6_cksum_phdr(&inp->inp_laddr6, - &inp->inp_faddr6, htonl(sizeof(struct tcphdr)), + n->th_sum = in6_cksum_phdr(&in6p_laddr(inp), + &in6p_faddr(inp), htonl(sizeof(struct tcphdr)), htonl(IPPROTO_TCP)); break; } @@ -823,7 +823,7 @@ tcp_respond(struct tcpcb *tp, struct mbuf *mtemplate, struct mbuf *m, if (tp != NULL && tp->t_inpcb->inp_af == AF_INET) { ro = &tp->t_inpcb->inp_route; KASSERT(family == AF_INET); - KASSERT(in_hosteq(ip->ip_dst, tp->t_inpcb->inp_faddr)); + KASSERT(in_hosteq(ip->ip_dst, in4p_faddr(tp->t_inpcb))); } #ifdef INET6 else if (tp != NULL && tp->t_inpcb->inp_af == AF_INET6) { @@ -831,16 +831,16 @@ tcp_respond(struct tcpcb *tp, struct mbuf *mtemplate, struct mbuf *m, #ifdef DIAGNOSTIC if (family == AF_INET) { - if (!IN6_IS_ADDR_V4MAPPED(&tp->t_inpcb->inp_faddr6)) + if (!IN6_IS_ADDR_V4MAPPED(&in6p_faddr(tp->t_inpcb))) panic("tcp_respond: not mapped addr"); if (memcmp(&ip->ip_dst, - &tp->t_inpcb->inp_faddr6.s6_addr32[3], + &in6p_faddr(tp->t_inpcb).s6_addr32[3], sizeof(ip->ip_dst)) != 0) { panic("tcp_respond: ip_dst != in6p_faddr"); } } else if (family == AF_INET6) { if (!IN6_ARE_ADDR_EQUAL(&ip6->ip6_dst, - &tp->t_inpcb->inp_faddr6)) + &in6p_faddr(tp->t_inpcb))) panic("tcp_respond: ip6_dst != in6p_faddr"); } else panic("tcp_respond: address family mismatch"); @@ -967,7 +967,7 @@ tcp_newtcpcb(int family, struct inpcb *inp) switch (family) { case AF_INET: - inp->inp_ip.ip_ttl = ip_defttl; + in4p_ip(inp).ip_ttl = ip_defttl; inp->inp_ppcb = (void *)tp; tp->t_inpcb = inp; @@ -975,7 +975,7 @@ tcp_newtcpcb(int family, struct inpcb *inp) break; #ifdef INET6 case AF_INET6: - inp->inp_ip6.ip6_hlim = in6_selecthlim_rt(inp); + in6p_ip6(inp).ip6_hlim = in6_selecthlim_rt(inp); inp->inp_ppcb = (void *)tp; tp->t_inpcb = inp; @@ -1843,7 +1843,7 @@ tcp_established(struct tcpcb *tp) rt = in_pcbrtentry(tp->t_inpcb); #endif if (__predict_true(tcp_msl_enable)) { - if (tp->t_inpcb->inp_laddr.s_addr == INADDR_LOOPBACK) { + if (in4p_laddr(tp->t_inpcb).s_addr == INADDR_LOOPBACK) { tp->t_msl = tcp_msl_loop ? tcp_msl_loop : (TCPTV_MSL >> 2); break; } @@ -1853,7 +1853,7 @@ tcp_established(struct tcpcb *tp) tp->t_msl = tcp_msl_local ? tcp_msl_local : (TCPTV_MSL >> 1); break; } - if (in_localaddr(tp->t_inpcb->inp_faddr)) { + if (in_localaddr(in4p_faddr(tp->t_inpcb))) { tp->t_msl = tcp_msl_local ? tcp_msl_local : (TCPTV_MSL >> 1); break; } @@ -1874,7 +1874,7 @@ tcp_established(struct tcpcb *tp) if (__predict_true(tcp_msl_enable)) { extern const struct in6_addr in6addr_loopback; - if (IN6_ARE_ADDR_EQUAL(&tp->t_inpcb->inp_laddr6, + if (IN6_ARE_ADDR_EQUAL(&in6p_laddr(tp->t_inpcb), &in6addr_loopback)) { tp->t_msl = tcp_msl_loop ? tcp_msl_loop : (TCPTV_MSL >> 2); break; @@ -1885,7 +1885,7 @@ tcp_established(struct tcpcb *tp) tp->t_msl = tcp_msl_local ? tcp_msl_local : (TCPTV_MSL >> 1); break; } - if (in6_localaddr(&tp->t_inpcb->inp_faddr6)) { + if (in6_localaddr(&in6p_faddr(tp->t_inpcb))) { tp->t_msl = tcp_msl_local ? tcp_msl_local : (TCPTV_MSL >> 1); break; } @@ -1977,15 +1977,15 @@ tcp_new_iss(struct tcpcb *tp) { if (tp->t_inpcb->inp_af == AF_INET) { - return tcp_new_iss1(&tp->t_inpcb->inp_laddr, - &tp->t_inpcb->inp_faddr, tp->t_inpcb->inp_lport, - tp->t_inpcb->inp_fport, sizeof(tp->t_inpcb->inp_laddr)); + return tcp_new_iss1(&in4p_laddr(tp->t_inpcb), + &in4p_faddr(tp->t_inpcb), tp->t_inpcb->inp_lport, + tp->t_inpcb->inp_fport, sizeof(in4p_laddr(tp->t_inpcb))); } #ifdef INET6 if (tp->t_inpcb->inp_af == AF_INET6) { - return tcp_new_iss1(&tp->t_inpcb->inp_laddr6, - &tp->t_inpcb->inp_faddr6, tp->t_inpcb->inp_lport, - tp->t_inpcb->inp_fport, sizeof(tp->t_inpcb->inp_laddr6)); + return tcp_new_iss1(&in6p_laddr(tp->t_inpcb), + &in6p_faddr(tp->t_inpcb), tp->t_inpcb->inp_lport, + tp->t_inpcb->inp_fport, sizeof(in6p_laddr(tp->t_inpcb))); } #endif diff --git a/sys/netinet/tcp_syncache.c b/sys/netinet/tcp_syncache.c index 14904c6eeba..6f2796a4289 100644 --- a/sys/netinet/tcp_syncache.c +++ b/sys/netinet/tcp_syncache.c @@ -610,7 +610,7 @@ syn_cache_get(struct sockaddr *src, struct sockaddr *dst, switch (src->sa_family) { case AF_INET: if (inp->inp_af == AF_INET) { - inp->inp_laddr = ((struct sockaddr_in *)dst)->sin_addr; + in4p_laddr(inp) = ((struct sockaddr_in *)dst)->sin_addr; inp->inp_lport = ((struct sockaddr_in *)dst)->sin_port; inp->inp_options = ip_srcroute(m); in_pcbstate(inp, INP_BOUND); @@ -622,10 +622,10 @@ syn_cache_get(struct sockaddr *src, struct sockaddr *dst, #ifdef INET6 else if (inp->inp_af == AF_INET6) { /* IPv4 packet to AF_INET6 socket */ - memset(&inp->inp_laddr6, 0, sizeof(inp->inp_laddr6)); - inp->inp_laddr6.s6_addr16[5] = htons(0xffff); + memset(&in6p_laddr(inp), 0, sizeof(in6p_laddr(inp))); + in6p_laddr(inp).s6_addr16[5] = htons(0xffff); bcopy(&((struct sockaddr_in *)dst)->sin_addr, - &inp->inp_laddr6.s6_addr32[3], + &in6p_laddr(inp).s6_addr32[3], sizeof(((struct sockaddr_in *)dst)->sin_addr)); inp->inp_lport = ((struct sockaddr_in *)dst)->sin_port; intotcpcb(inp)->t_family = AF_INET; @@ -640,7 +640,7 @@ syn_cache_get(struct sockaddr *src, struct sockaddr *dst, #ifdef INET6 case AF_INET6: if (inp->inp_af == AF_INET6) { - inp->inp_laddr6 = ((struct sockaddr_in6 *)dst)->sin6_addr; + in6p_laddr(inp) = ((struct sockaddr_in6 *)dst)->sin6_addr; inp->inp_lport = ((struct sockaddr_in6 *)dst)->sin6_port; in_pcbstate(inp, INP_BOUND); } @@ -746,10 +746,10 @@ syn_cache_get(struct sockaddr *src, struct sockaddr *dst, tp->snd_cwnd = tp->t_peermss; else { int ss = tcp_init_win; - if (inp->inp_af == AF_INET && in_localaddr(inp->inp_faddr)) + if (inp->inp_af == AF_INET && in_localaddr(in4p_faddr(inp))) ss = tcp_init_win_local; #ifdef INET6 - else if (inp->inp_af == AF_INET6 && in6_localaddr(&inp->inp_faddr6)) + else if (inp->inp_af == AF_INET6 && in6_localaddr(&in6p_faddr(inp))) ss = tcp_init_win_local; #endif tp->snd_cwnd = TCP_INITIAL_WINDOW(ss, tp->t_peermss); diff --git a/sys/netinet/tcp_timer.c b/sys/netinet/tcp_timer.c index 6e89e1a4093..329ce956222 100644 --- a/sys/netinet/tcp_timer.c +++ b/sys/netinet/tcp_timer.c @@ -330,7 +330,7 @@ tcp_timer_rexmt(void *arg) icmp.icmp_nextmtu = tp->t_pmtud_nextmtu; icmp.icmp_ip.ip_len = tp->t_pmtud_ip_len; icmp.icmp_ip.ip_hl = tp->t_pmtud_ip_hl; - icmpsrc.sin_addr = tp->t_inpcb->inp_faddr; + icmpsrc.sin_addr = in4p_faddr(tp->t_inpcb); icmp_mtudisc(&icmp, icmpsrc.sin_addr); /* diff --git a/sys/netinet/tcp_usrreq.c b/sys/netinet/tcp_usrreq.c index 3075156ce2e..6c0ee485ed0 100644 --- a/sys/netinet/tcp_usrreq.c +++ b/sys/netinet/tcp_usrreq.c @@ -573,7 +573,7 @@ tcp_bind(struct socket *so, struct sockaddr *nam, struct lwp *l) error = in6_pcbbind(inp, sin6, l); if (!error) { /* mapped addr case */ - if (IN6_IS_ADDR_V4MAPPED(&inp->inp_laddr6)) + if (IN6_IS_ADDR_V4MAPPED(&in6p_laddr(inp))) tp->t_family = AF_INET; else tp->t_family = AF_INET6; @@ -667,7 +667,7 @@ tcp_connect(struct socket *so, struct sockaddr *nam, struct lwp *l) error = in6_pcbconnect(inp, (struct sockaddr_in6 *)nam, l); if (!error) { /* mapped addr case */ - if (IN6_IS_ADDR_V4MAPPED(&inp->inp_faddr6)) + if (IN6_IS_ADDR_V4MAPPED(&in6p_faddr(inp))) tp->t_family = AF_INET; else tp->t_family = AF_INET6; @@ -1665,13 +1665,13 @@ sysctl_inpcblist(SYSCTLFN_ARGS) in->sin_len = sizeof(*in); in->sin_family = pf; in->sin_port = inp->inp_lport; - in->sin_addr = inp->inp_laddr; + in->sin_addr = const_in4p_laddr(inp); if (pcb.ki_prstate >= INP_CONNECTED) { in = satosin(&pcb.ki_dst); in->sin_len = sizeof(*in); in->sin_family = pf; in->sin_port = inp->inp_fport; - in->sin_addr = inp->inp_faddr; + in->sin_addr = const_in4p_faddr(inp); } break; #ifdef INET6 @@ -1705,8 +1705,8 @@ sysctl_inpcblist(SYSCTLFN_ARGS) in6->sin6_len = sizeof(*in6); in6->sin6_family = pf; in6->sin6_port = inp->inp_lport; - in6->sin6_flowinfo = inp->inp_flowinfo; - in6->sin6_addr = inp->inp_laddr6; + in6->sin6_flowinfo = const_in6p_flowinfo(inp); + in6->sin6_addr = const_in6p_laddr(inp); in6->sin6_scope_id = 0; /* XXX? */ if (pcb.ki_prstate >= INP_CONNECTED) { @@ -1714,8 +1714,8 @@ sysctl_inpcblist(SYSCTLFN_ARGS) in6->sin6_len = sizeof(*in6); in6->sin6_family = pf; in6->sin6_port = inp->inp_fport; - in6->sin6_flowinfo = inp->inp_flowinfo; - in6->sin6_addr = inp->inp_faddr6; + in6->sin6_flowinfo = const_in6p_flowinfo(inp); + in6->sin6_addr = const_in6p_faddr(inp); in6->sin6_scope_id = 0; /* XXX? */ } break; diff --git a/sys/netinet/tcp_vtw.c b/sys/netinet/tcp_vtw.c index 173b7c07afa..a08d9e44ef6 100644 --- a/sys/netinet/tcp_vtw.c +++ b/sys/netinet/tcp_vtw.c @@ -1900,8 +1900,8 @@ vtw_add(int af, struct tcpcb *tp) struct inpcb *inp = tp->t_inpcb; vtw_v4_t *v4 = (void*)vtw; - v4->faddr = inp->inp_faddr.s_addr; - v4->laddr = inp->inp_laddr.s_addr; + v4->faddr = in4p_faddr(inp).s_addr; + v4->laddr = in4p_laddr(inp).s_addr; v4->fport = inp->inp_fport; v4->lport = inp->inp_lport; @@ -1922,14 +1922,14 @@ vtw_add(int af, struct tcpcb *tp) if (enable & 4) { KASSERT(vtw_lookup_hash_v4 (ctl - , inp->inp_faddr.s_addr, inp->inp_fport - , inp->inp_laddr.s_addr, inp->inp_lport + , in4p_faddr(inp).s_addr, inp->inp_fport + , in4p_laddr(inp).s_addr, inp->inp_lport , 0) == vtw); KASSERT(vtw_lookup_hash_v4 (ctl - , inp->inp_faddr.s_addr, inp->inp_fport - , inp->inp_laddr.s_addr, inp->inp_lport + , in4p_faddr(inp).s_addr, inp->inp_fport + , in4p_laddr(inp).s_addr, inp->inp_lport , 1)); } /* Immediate port iterator functionality check: not wild @@ -1939,7 +1939,7 @@ vtw_add(int af, struct tcpcb *tp) struct vestigial_inpcb res; int cnt = 0; - it = tcp_init_ports_v4(inp->inp_laddr + it = tcp_init_ports_v4(in4p_laddr(inp) , inp->inp_lport, 0); while (tcp_next_port_v4(it, &res)) { @@ -1972,8 +1972,8 @@ vtw_add(int af, struct tcpcb *tp) struct inpcb *inp = tp->t_inpcb; vtw_v6_t *v6 = (void*)vtw; - v6->faddr = inp->inp_faddr6; - v6->laddr = inp->inp_laddr6; + v6->faddr = in6p_faddr(inp); + v6->laddr = in6p_laddr(inp); v6->fport = inp->inp_fport; v6->lport = inp->inp_lport; @@ -1992,14 +1992,14 @@ vtw_add(int af, struct tcpcb *tp) */ if (enable & 4) { KASSERT(vtw_lookup_hash_v6(ctl - , &inp->inp_faddr6, inp->inp_fport - , &inp->inp_laddr6, inp->inp_lport + , &in6p_faddr(inp), inp->inp_fport + , &in6p_laddr(inp), inp->inp_lport , 0) == vtw); KASSERT(vtw_lookup_hash_v6 (ctl - , &inp->inp_faddr6, inp->inp_fport - , &inp->inp_laddr6, inp->inp_lport + , &in6p_faddr(inp), inp->inp_fport + , &in6p_laddr(inp), inp->inp_lport , 1)); } /* Immediate port iterator functionality check: not wild @@ -2009,7 +2009,7 @@ vtw_add(int af, struct tcpcb *tp) struct vestigial_inpcb res; int cnt = 0; - it = tcp_init_ports_v6(&inp->inp_laddr6 + it = tcp_init_ports_v6(&in6p_laddr(inp) , inp->inp_lport, 0); while (tcp_next_port_v6(it, &res)) { diff --git a/sys/netinet/udp_usrreq.c b/sys/netinet/udp_usrreq.c index 7648f5c281b..67b3da01098 100644 --- a/sys/netinet/udp_usrreq.c +++ b/sys/netinet/udp_usrreq.c @@ -533,12 +533,12 @@ udp4_realinput(struct sockaddr_in *src, struct sockaddr_in *dst, if (inp->inp_lport != *dport) continue; - if (!in_nullhost(inp->inp_laddr)) { - if (!in_hosteq(inp->inp_laddr, *dst4)) + if (!in_nullhost(in4p_laddr(inp))) { + if (!in_hosteq(in4p_laddr(inp), *dst4)) continue; } - if (!in_nullhost(inp->inp_faddr)) { - if (!in_hosteq(inp->inp_faddr, *src4) || + if (!in_nullhost(in4p_faddr(inp))) { + if (!in_hosteq(in4p_faddr(inp), *src4) || inp->inp_fport != *sport) continue; } @@ -623,7 +623,7 @@ udp4_realinput(struct sockaddr_in *src, struct sockaddr_in *dst, /* * Check the minimum TTL for socket. */ - if (mtod(m, struct ip *)->ip_ttl < inp->inp_ip_minttl) + if (mtod(m, struct ip *)->ip_ttl < in4p_ip_minttl(inp)) goto bad; udp4_sendup(m, off, (struct sockaddr *)src, inp->inp_socket); @@ -816,7 +816,7 @@ udp_output(struct mbuf *m, struct inpcb *inp, struct mbuf *control, ui = mtod(m, struct udpiphdr *); ui->ui_pr = IPPROTO_UDP; ui->ui_src = pktopts.ippo_laddr.sin_addr; - ui->ui_dst = inp->inp_faddr; + ui->ui_dst = in4p_faddr(inp); ui->ui_sport = inp->inp_lport; ui->ui_dport = inp->inp_fport; ui->ui_ulen = htons((u_int16_t)len + sizeof(struct udphdr)); @@ -840,8 +840,8 @@ udp_output(struct mbuf *m, struct inpcb *inp, struct mbuf *control, ui->ui_sum = 0; ((struct ip *)ui)->ip_len = htons(sizeof(struct udpiphdr) + len); - ((struct ip *)ui)->ip_ttl = inp->inp_ip.ip_ttl; /* XXX */ - ((struct ip *)ui)->ip_tos = inp->inp_ip.ip_tos; /* XXX */ + ((struct ip *)ui)->ip_ttl = in4p_ip(inp).ip_ttl; /* XXX */ + ((struct ip *)ui)->ip_tos = in4p_ip(inp).ip_tos; /* XXX */ UDP_STATINC(UDP_STAT_OPACKETS); flags |= inp->inp_socket->so_options & (SO_DONTROUTE|SO_BROADCAST); @@ -882,7 +882,7 @@ udp_attach(struct socket *so, int proto) return error; } inp = sotoinpcb(so); - inp->inp_ip.ip_ttl = ip_defttl; + in4p_ip(inp).ip_ttl = ip_defttl; KASSERT(solocked(so)); return error; @@ -976,7 +976,7 @@ udp_disconnect(struct socket *so) /*soisdisconnected(so);*/ so->so_state &= ~SS_ISCONNECTED; /* XXX */ in_pcbdisconnect(inp); - inp->inp_laddr = zeroin_addr; /* XXX */ + in4p_laddr(inp) = zeroin_addr; /* XXX */ in_pcbstate(inp, INP_BOUND); /* XXX */ splx(s); @@ -1087,7 +1087,7 @@ udp_send(struct socket *so, struct mbuf *m, struct sockaddr *nam, s = splsoftnet(); if (nam) { - laddr = inp->inp_laddr; /* XXX */ + laddr = in4p_laddr(inp); /* XXX */ if ((so->so_state & SS_ISCONNECTED) != 0) { error = EISCONN; goto die; @@ -1106,7 +1106,7 @@ udp_send(struct socket *so, struct mbuf *m, struct sockaddr *nam, control = NULL; if (nam) { in_pcbdisconnect(inp); - inp->inp_laddr = laddr; /* XXX */ + in4p_laddr(inp) = laddr; /* XXX */ in_pcbstate(inp, INP_BOUND); /* XXX */ } die: diff --git a/sys/netinet6/dccp6_usrreq.c b/sys/netinet6/dccp6_usrreq.c index 31775f0723a..a7628b2bb90 100644 --- a/sys/netinet6/dccp6_usrreq.c +++ b/sys/netinet6/dccp6_usrreq.c @@ -162,7 +162,7 @@ dccp6_connect(struct socket *so, struct sockaddr *nam, struct lwp *l) return EINVAL; } INP_LOCK(inp); - if (inp->inp_faddr6.s_addr != INADDR_ANY) { + if (in6p_faddr(inp).s_addr != INADDR_ANY) { INP_UNLOCK(inp); INP_INFO_WUNLOCK(&dccpbinfo); return EISCONN; @@ -174,7 +174,7 @@ dccp6_connect(struct socket *so, struct sockaddr *nam, struct lwp *l) if (inp == 0) { return EINVAL; } - if (!IN6_IS_ADDR_UNSPECIFIED(&inp->inp_faddr6)) { + if (!IN6_IS_ADDR_UNSPECIFIED(&in6p_faddr(inp))) { return EISCONN; } diff --git a/sys/netinet6/icmp6.c b/sys/netinet6/icmp6.c index 42bdfb59cb9..b8b36e8d045 100644 --- a/sys/netinet6/icmp6.c +++ b/sys/netinet6/icmp6.c @@ -1965,17 +1965,17 @@ icmp6_rip6_input(struct mbuf **mp, int off) TAILQ_FOREACH(inp, &raw6cbtable.inpt_queue, inp_queue) { if (inp->inp_af != AF_INET6) continue; - if (inp->inp_ip6.ip6_nxt != IPPROTO_ICMPV6) + if (in6p_ip6(inp).ip6_nxt != IPPROTO_ICMPV6) continue; - if (!IN6_IS_ADDR_UNSPECIFIED(&inp->inp_laddr6) && - !IN6_ARE_ADDR_EQUAL(&inp->inp_laddr6, &ip6->ip6_dst)) + if (!IN6_IS_ADDR_UNSPECIFIED(&in6p_laddr(inp)) && + !IN6_ARE_ADDR_EQUAL(&in6p_laddr(inp), &ip6->ip6_dst)) continue; - if (!IN6_IS_ADDR_UNSPECIFIED(&inp->inp_faddr6) && - !IN6_ARE_ADDR_EQUAL(&inp->inp_faddr6, &ip6->ip6_src)) + if (!IN6_IS_ADDR_UNSPECIFIED(&in6p_faddr(inp)) && + !IN6_ARE_ADDR_EQUAL(&in6p_faddr(inp), &ip6->ip6_src)) continue; - if (inp->inp_icmp6filt && + if (in6p_icmp6filt(inp) && ICMP6_FILTER_WILLBLOCK(icmp6->icmp6_type, - inp->inp_icmp6filt)) + in6p_icmp6filt(inp))) continue; if (last == NULL) { @@ -2755,7 +2755,7 @@ icmp6_ctloutput(int op, struct socket *so, struct sockopt *sopt) error = sockopt_get(sopt, &fil, sizeof(fil)); if (error) break; - memcpy(inp->inp_icmp6filt, &fil, + memcpy(in6p_icmp6filt(inp), &fil, sizeof(struct icmp6_filter)); error = 0; break; @@ -2771,11 +2771,11 @@ icmp6_ctloutput(int op, struct socket *so, struct sockopt *sopt) switch (sopt->sopt_name) { case ICMP6_FILTER: { - if (inp->inp_icmp6filt == NULL) { + if (in6p_icmp6filt(inp) == NULL) { error = EINVAL; break; } - error = sockopt_set(sopt, inp->inp_icmp6filt, + error = sockopt_set(sopt, in6p_icmp6filt(inp), sizeof(struct icmp6_filter)); break; } diff --git a/sys/netinet6/in6_pcb.c b/sys/netinet6/in6_pcb.c index 76264a3ade5..1ed7203ab98 100644 --- a/sys/netinet6/in6_pcb.c +++ b/sys/netinet6/in6_pcb.c @@ -219,7 +219,7 @@ in6_pcbbind_addr(struct inpcb *inp, struct sockaddr_in6 *sin6, struct lwp *l) goto out; } } - inp->inp_laddr6 = sin6->sin6_addr; + in6p_laddr(inp) = sin6->sin6_addr; error = 0; out: pserialize_read_exit(s); @@ -336,9 +336,9 @@ in6_pcbbind(void *v, struct sockaddr_in6 *sin6, struct lwp *l) * If we already have a local port or a local address it means we're * bounded. */ - if (inp->inp_lport || !(IN6_IS_ADDR_UNSPECIFIED(&inp->inp_laddr6) || - (IN6_IS_ADDR_V4MAPPED(&inp->inp_laddr6) && - inp->inp_laddr6.s6_addr32[3] == 0))) + if (inp->inp_lport || !(IN6_IS_ADDR_UNSPECIFIED(&in6p_laddr(inp)) || + (IN6_IS_ADDR_V4MAPPED(&in6p_laddr(inp)) && + in6p_laddr(inp).s6_addr32[3] == 0))) return (EINVAL); if (NULL != sin6) { @@ -364,14 +364,14 @@ in6_pcbbind(void *v, struct sockaddr_in6 *sin6, struct lwp *l) * Reset the address here to "any" so we don't "leak" the * inpcb. */ - inp->inp_laddr6 = in6addr_any; + in6p_laddr(inp) = in6addr_any; return (error); } #if 0 - inp->inp_flowinfo = 0; /* XXX */ + in6p_flowinfo(inp) = 0; /* XXX */ #endif return (0); } @@ -424,13 +424,13 @@ in6_pcbconnect(void *v, struct sockaddr_in6 *sin6, struct lwp *l) if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) { if ((inp->inp_flags & IN6P_IPV6_V6ONLY) != 0) return EINVAL; - if (IN6_IS_ADDR_UNSPECIFIED(&inp->inp_laddr6)) - inp->inp_laddr6.s6_addr16[5] = htons(0xffff); - if (!IN6_IS_ADDR_V4MAPPED(&inp->inp_laddr6)) + if (IN6_IS_ADDR_UNSPECIFIED(&in6p_laddr(inp))) + in6p_laddr(inp).s6_addr16[5] = htons(0xffff); + if (!IN6_IS_ADDR_V4MAPPED(&in6p_laddr(inp))) return EINVAL; } else { - if (IN6_IS_ADDR_V4MAPPED(&inp->inp_laddr6)) + if (IN6_IS_ADDR_V4MAPPED(&in6p_laddr(inp))) return EINVAL; } @@ -440,8 +440,8 @@ in6_pcbconnect(void *v, struct sockaddr_in6 *sin6, struct lwp *l) bound = curlwp_bind(); /* Source address selection. */ - if (IN6_IS_ADDR_V4MAPPED(&inp->inp_laddr6) && - inp->inp_laddr6.s6_addr32[3] == 0) { + if (IN6_IS_ADDR_V4MAPPED(&in6p_laddr(inp)) && + in6p_laddr(inp).s6_addr32[3] == 0) { #ifdef INET struct sockaddr_in sin; struct in_ifaddr *ia4; @@ -476,8 +476,8 @@ in6_pcbconnect(void *v, struct sockaddr_in6 *sin6, struct lwp *l) * with the address specified by setsockopt(IPV6_PKTINFO). * Is it the intended behavior? */ - error = in6_selectsrc(sin6, inp->inp_outputopts6, - inp->inp_moptions6, &inp->inp_route, &inp->inp_laddr6, + error = in6_selectsrc(sin6, in6p_outputopts(inp), + in6p_moptions(inp), &inp->inp_route, &in6p_laddr(inp), &ifp, &psref, &ia6); if (error == 0) in6a = &ia6; @@ -498,37 +498,37 @@ in6_pcbconnect(void *v, struct sockaddr_in6 *sin6, struct lwp *l) } if (ifp != NULL) { - inp->inp_ip6.ip6_hlim = (u_int8_t)in6_selecthlim(inp, ifp); + in6p_ip6(inp).ip6_hlim = (u_int8_t)in6_selecthlim(inp, ifp); if_put(ifp, &psref); } else - inp->inp_ip6.ip6_hlim = (u_int8_t)in6_selecthlim_rt(inp); + in6p_ip6(inp).ip6_hlim = (u_int8_t)in6_selecthlim_rt(inp); curlwp_bindx(bound); if (in6_pcblookup_connect(inp->inp_table, &sin6->sin6_addr, sin6->sin6_port, - IN6_IS_ADDR_UNSPECIFIED(&inp->inp_laddr6) ? in6a : &inp->inp_laddr6, + IN6_IS_ADDR_UNSPECIFIED(&in6p_laddr(inp)) ? in6a : &in6p_laddr(inp), inp->inp_lport, 0, &vestige) || vestige.valid) return (EADDRINUSE); - if (IN6_IS_ADDR_UNSPECIFIED(&inp->inp_laddr6) || - (IN6_IS_ADDR_V4MAPPED(&inp->inp_laddr6) && - inp->inp_laddr6.s6_addr32[3] == 0)) + if (IN6_IS_ADDR_UNSPECIFIED(&in6p_laddr(inp)) || + (IN6_IS_ADDR_V4MAPPED(&in6p_laddr(inp)) && + in6p_laddr(inp).s6_addr32[3] == 0)) { if (inp->inp_lport == 0) { error = in6_pcbbind(inp, NULL, l); if (error != 0) return error; } - inp->inp_laddr6 = *in6a; + in6p_laddr(inp) = *in6a; } - inp->inp_faddr6 = sin6->sin6_addr; + in6p_faddr(inp) = sin6->sin6_addr; inp->inp_fport = sin6->sin6_port; /* Late bind, if needed */ if (inp->inp_bindportonsend) { struct sockaddr_in6 lsin = *((const struct sockaddr_in6 *) inp->inp_socket->so_proto->pr_domain->dom_sa_any); - lsin.sin6_addr = inp->inp_laddr6; + lsin.sin6_addr = in6p_laddr(inp); lsin.sin6_port = 0; if ((error = in6_pcbbind_port(inp, &lsin, l)) != 0) @@ -536,9 +536,9 @@ in6_pcbconnect(void *v, struct sockaddr_in6 *sin6, struct lwp *l) } in_pcbstate(inp, INP_CONNECTED); - inp->inp_flowinfo &= ~IPV6_FLOWLABEL_MASK; + in6p_flowinfo(inp) &= ~IPV6_FLOWLABEL_MASK; if (ip6_auto_flowlabel) - inp->inp_flowinfo |= + in6p_flowinfo(inp) |= (htonl(ip6_randomflowlabel()) & IPV6_FLOWLABEL_MASK); #if defined(IPSEC) if (ipsec_enabled && inp->inp_socket->so_type == SOCK_STREAM) @@ -550,10 +550,10 @@ in6_pcbconnect(void *v, struct sockaddr_in6 *sin6, struct lwp *l) void in6_pcbdisconnect(struct inpcb *inp) { - memset((void *)&inp->inp_faddr6, 0, sizeof(inp->inp_faddr6)); + memset((void *)&in6p_faddr(inp), 0, sizeof(in6p_faddr(inp))); inp->inp_fport = 0; in_pcbstate(inp, INP_BOUND); - inp->inp_flowinfo &= ~IPV6_FLOWLABEL_MASK; + in6p_flowinfo(inp) &= ~IPV6_FLOWLABEL_MASK; #if defined(IPSEC) if (ipsec_enabled) ipsec_pcbdisconn(inp->inp_sp); @@ -569,7 +569,7 @@ in6_setsockaddr(struct inpcb *inp, struct sockaddr_in6 *sin6) if (inp->inp_af != AF_INET6) return; - sockaddr_in6_init(sin6, &inp->inp_laddr6, inp->inp_lport, 0, 0); + sockaddr_in6_init(sin6, &in6p_laddr(inp), inp->inp_lport, 0, 0); (void)sa6_recoverscope(sin6); /* XXX: should catch errors */ } @@ -580,7 +580,7 @@ in6_setpeeraddr(struct inpcb *inp, struct sockaddr_in6 *sin6) if (inp->inp_af != AF_INET6) return; - sockaddr_in6_init(sin6, &inp->inp_faddr6, inp->inp_fport, 0, 0); + sockaddr_in6_init(sin6, &in6p_faddr(inp), inp->inp_fport, 0, 0); (void)sa6_recoverscope(sin6); /* XXX: should catch errors */ } @@ -680,7 +680,7 @@ in6_pcbnotify(struct inpcbtable *table, const struct sockaddr *dst, * icmp6_mtudisc_update(). */ if ((PRC_IS_REDIRECT(cmd) || cmd == PRC_HOSTDEAD) && - IN6_IS_ADDR_UNSPECIFIED(&inp->inp_laddr6) && + IN6_IS_ADDR_UNSPECIFIED(&in6p_laddr(inp)) && (rt = rtcache_validate(&inp->inp_route)) != NULL && !(rt->rt_flags & RTF_HOST)) { const struct sockaddr_in6 *dst6; @@ -707,8 +707,8 @@ in6_pcbnotify(struct inpcbtable *table, const struct sockaddr *dst, * XXX: should we avoid to notify the value to TCP sockets? */ if (cmd == PRC_MSGSIZE && (inp->inp_flags & IN6P_MTU) != 0 && - (IN6_IS_ADDR_UNSPECIFIED(&inp->inp_faddr6) || - IN6_ARE_ADDR_EQUAL(&inp->inp_faddr6, &sa6_dst->sin6_addr))) { + (IN6_IS_ADDR_UNSPECIFIED(&in6p_faddr(inp)) || + IN6_ARE_ADDR_EQUAL(&in6p_faddr(inp), &sa6_dst->sin6_addr))) { ip6_notify_pmtu(inp, (const struct sockaddr_in6 *)dst, (u_int32_t *)cmdarg); } @@ -723,15 +723,15 @@ in6_pcbnotify(struct inpcbtable *table, const struct sockaddr *dst, */ if (lport == 0 && fport == 0 && flowinfo && inp->inp_socket != NULL && - flowinfo == (inp->inp_flowinfo & IPV6_FLOWLABEL_MASK) && - IN6_ARE_ADDR_EQUAL(&inp->inp_laddr6, &sa6_src.sin6_addr)) + flowinfo == (in6p_flowinfo(inp) & IPV6_FLOWLABEL_MASK) && + IN6_ARE_ADDR_EQUAL(&in6p_laddr(inp), &sa6_src.sin6_addr)) goto do_notify; - else if (!IN6_ARE_ADDR_EQUAL(&inp->inp_faddr6, + else if (!IN6_ARE_ADDR_EQUAL(&in6p_faddr(inp), &sa6_dst->sin6_addr) || inp->inp_socket == NULL || (lport && inp->inp_lport != lport) || (!IN6_IS_ADDR_UNSPECIFIED(&sa6_src.sin6_addr) && - !IN6_ARE_ADDR_EQUAL(&inp->inp_laddr6, + !IN6_ARE_ADDR_EQUAL(&in6p_laddr(inp), &sa6_src.sin6_addr)) || (fport && inp->inp_fport != fport)) continue; @@ -763,7 +763,7 @@ in6_pcbpurgeif0(struct inpcbtable *table, struct ifnet *ifp) inp_lock(inp); need_unlock = true; } - im6o = inp->inp_moptions6; + im6o = in6p_moptions(inp); if (im6o) { /* * Unselect the outgoing interface if it is being @@ -849,13 +849,13 @@ in6_pcblookup_port(struct inpcbtable *table, struct in6_addr *laddr6, if (inp->inp_lport != lport) continue; wildcard = 0; - if (IN6_IS_ADDR_V4MAPPED(&inp->inp_faddr6)) { + if (IN6_IS_ADDR_V4MAPPED(&in6p_faddr(inp))) { if ((inp->inp_flags & IN6P_IPV6_V6ONLY) != 0) continue; } - if (!IN6_IS_ADDR_UNSPECIFIED(&inp->inp_faddr6)) + if (!IN6_IS_ADDR_UNSPECIFIED(&in6p_faddr(inp))) wildcard++; - if (IN6_IS_ADDR_V4MAPPED(&inp->inp_laddr6)) { + if (IN6_IS_ADDR_V4MAPPED(&in6p_laddr(inp))) { if ((inp->inp_flags & IN6P_IPV6_V6ONLY) != 0) continue; if (!IN6_IS_ADDR_V4MAPPED(laddr6)) @@ -863,22 +863,22 @@ in6_pcblookup_port(struct inpcbtable *table, struct in6_addr *laddr6, /* duplicate of IPv4 logic */ wildcard = 0; - if (IN6_IS_ADDR_V4MAPPED(&inp->inp_faddr6) && - inp->inp_faddr6.s6_addr32[3]) + if (IN6_IS_ADDR_V4MAPPED(&in6p_faddr(inp)) && + in6p_faddr(inp).s6_addr32[3]) wildcard++; - if (!inp->inp_laddr6.s6_addr32[3]) { + if (!in6p_laddr(inp).s6_addr32[3]) { if (laddr6->s6_addr32[3]) wildcard++; } else { if (!laddr6->s6_addr32[3]) wildcard++; else { - if (inp->inp_laddr6.s6_addr32[3] != + if (in6p_laddr(inp).s6_addr32[3] != laddr6->s6_addr32[3]) continue; } } - } else if (IN6_IS_ADDR_UNSPECIFIED(&inp->inp_laddr6)) { + } else if (IN6_IS_ADDR_UNSPECIFIED(&in6p_laddr(inp))) { if (IN6_IS_ADDR_V4MAPPED(laddr6)) { if ((inp->inp_flags & IN6P_IPV6_V6ONLY) != 0) continue; @@ -893,7 +893,7 @@ in6_pcblookup_port(struct inpcbtable *table, struct in6_addr *laddr6, if (IN6_IS_ADDR_UNSPECIFIED(laddr6)) wildcard++; else { - if (!IN6_ARE_ADDR_EQUAL(&inp->inp_laddr6, + if (!IN6_ARE_ADDR_EQUAL(&in6p_laddr(inp), laddr6)) continue; } @@ -988,27 +988,27 @@ in6_pcbrtentry(struct inpcb *inp) ; #ifdef INET else if (cdst.sa->sa_family == AF_INET) { - KASSERT(IN6_IS_ADDR_V4MAPPED(&inp->inp_faddr6)); - if (cdst.sa4->sin_addr.s_addr != inp->inp_faddr6.s6_addr32[3]) + KASSERT(IN6_IS_ADDR_V4MAPPED(&in6p_faddr(inp))); + if (cdst.sa4->sin_addr.s_addr != in6p_faddr(inp).s6_addr32[3]) rtcache_free(ro); } #endif else { if (!IN6_ARE_ADDR_EQUAL(&cdst.sa6->sin6_addr, - &inp->inp_faddr6)) + &in6p_faddr(inp))) rtcache_free(ro); } if ((rt = rtcache_validate(ro)) == NULL) rt = rtcache_update(ro, 1); #ifdef INET - if (rt == NULL && IN6_IS_ADDR_V4MAPPED(&inp->inp_faddr6)) { + if (rt == NULL && IN6_IS_ADDR_V4MAPPED(&in6p_faddr(inp))) { union { struct sockaddr dst; struct sockaddr_in dst4; } u; struct in_addr addr; - addr.s_addr = inp->inp_faddr6.s6_addr32[3]; + addr.s_addr = in6p_faddr(inp).s6_addr32[3]; sockaddr_in_init(&u.dst4, &addr, 0); if (rtcache_setdst(ro, &u.dst) != 0) @@ -1017,13 +1017,13 @@ in6_pcbrtentry(struct inpcb *inp) rt = rtcache_init(ro); } else #endif - if (rt == NULL && !IN6_IS_ADDR_UNSPECIFIED(&inp->inp_faddr6)) { + if (rt == NULL && !IN6_IS_ADDR_UNSPECIFIED(&in6p_faddr(inp))) { union { struct sockaddr dst; struct sockaddr_in6 dst6; } u; - sockaddr_in6_init(&u.dst6, &inp->inp_faddr6, 0, 0, 0); + sockaddr_in6_init(&u.dst6, &in6p_faddr(inp), 0, 0, 0); if (rtcache_setdst(ro, &u.dst) != 0) return NULL; @@ -1062,13 +1062,13 @@ in6_pcblookup_connect(struct inpcbtable *table, const struct in6_addr *faddr6, continue; if (inp->inp_lport != lport) continue; - if (IN6_IS_ADDR_UNSPECIFIED(&inp->inp_faddr6)) + if (IN6_IS_ADDR_UNSPECIFIED(&in6p_faddr(inp))) continue; - if (!IN6_ARE_ADDR_EQUAL(&inp->inp_faddr6, faddr6)) + if (!IN6_ARE_ADDR_EQUAL(&in6p_faddr(inp), faddr6)) continue; - if (IN6_IS_ADDR_UNSPECIFIED(&inp->inp_laddr6)) + if (IN6_IS_ADDR_UNSPECIFIED(&in6p_laddr(inp))) continue; - if (!IN6_ARE_ADDR_EQUAL(&inp->inp_laddr6, laddr6)) + if (!IN6_ARE_ADDR_EQUAL(&in6p_laddr(inp), laddr6)) continue; if ((IN6_IS_ADDR_V4MAPPED(laddr6) || IN6_IS_ADDR_V4MAPPED(faddr6)) && @@ -1110,7 +1110,7 @@ in6_pcblookup_bind(struct inpcbtable *table, const struct in6_addr *laddr6, if (IN6_IS_ADDR_V4MAPPED(laddr6) && (inp->inp_flags & IN6P_IPV6_V6ONLY) != 0) continue; - if (IN6_ARE_ADDR_EQUAL(&inp->inp_laddr6, laddr6)) + if (IN6_ARE_ADDR_EQUAL(&in6p_laddr(inp), laddr6)) goto out; } #ifdef INET @@ -1130,7 +1130,7 @@ in6_pcblookup_bind(struct inpcbtable *table, const struct in6_addr *laddr6, continue; if ((inp->inp_flags & IN6P_IPV6_V6ONLY) != 0) continue; - if (IN6_ARE_ADDR_EQUAL(&inp->inp_laddr6, &zero_mapped)) + if (IN6_ARE_ADDR_EQUAL(&in6p_laddr(inp), &zero_mapped)) goto out; } } @@ -1149,7 +1149,7 @@ in6_pcblookup_bind(struct inpcbtable *table, const struct in6_addr *laddr6, if (IN6_IS_ADDR_V4MAPPED(laddr6) && (inp->inp_flags & IN6P_IPV6_V6ONLY) != 0) continue; - if (IN6_ARE_ADDR_EQUAL(&inp->inp_laddr6, &zeroin6_addr)) + if (IN6_ARE_ADDR_EQUAL(&in6p_laddr(inp), &zeroin6_addr)) goto out; } return (NULL); @@ -1175,13 +1175,13 @@ in6_pcbstate(struct inpcb *inp, int state) switch (state) { case INP_BOUND: LIST_INSERT_HEAD(IN6PCBHASH_BIND(inp->inp_table, - &inp->inp_laddr6, inp->inp_lport), inp, + &in6p_laddr(inp), inp->inp_lport), inp, inp_hash); break; case INP_CONNECTED: LIST_INSERT_HEAD(IN6PCBHASH_CONNECT(inp->inp_table, - &inp->inp_faddr6, inp->inp_fport, - &inp->inp_laddr6, inp->inp_lport), inp, + &in6p_faddr(inp), inp->inp_fport, + &in6p_laddr(inp), inp->inp_lport), inp, inp_hash); break; } diff --git a/sys/netinet6/in6_src.c b/sys/netinet6/in6_src.c index 125e21d7f3d..ba5d8252368 100644 --- a/sys/netinet6/in6_src.c +++ b/sys/netinet6/in6_src.c @@ -811,8 +811,8 @@ out: int in6_selecthlim(struct inpcb *inp, struct ifnet *ifp) { - if (inp && inp->inp_hops6 >= 0) - return (inp->inp_hops6); + if (inp && in6p_hops6(inp) >= 0) + return in6p_hops6(inp); else if (ifp) return (ND_IFINFO(ifp)->chlim); else diff --git a/sys/netinet6/ip6_output.c b/sys/netinet6/ip6_output.c index 074fe7b38f0..bf3149421a0 100644 --- a/sys/netinet6/ip6_output.c +++ b/sys/netinet6/ip6_output.c @@ -1341,7 +1341,7 @@ ip6_ctloutput(int op, struct socket *so, struct sockopt *sopt) switch (optname) { #ifdef RFC2292 case IPV6_2292PKTOPTIONS: - error = ip6_pcbopts(&inp->inp_outputopts6, so, sopt); + error = ip6_pcbopts(&in6p_outputopts(inp), so, sopt); break; #endif @@ -1388,7 +1388,7 @@ ip6_ctloutput(int op, struct socket *so, struct sockopt *sopt) error = EINVAL; else { /* -1 = kernel default */ - inp->inp_hops6 = optval; + in6p_hops6(inp) = optval; } break; #define OPTSET(bit) \ @@ -1434,7 +1434,7 @@ else \ break; } #endif - optp = &inp->inp_outputopts6; + optp = &in6p_outputopts(inp); error = ip6_pcbopt(IPV6_HOPLIMIT, (u_char *)&optval, sizeof(optval), @@ -1520,7 +1520,7 @@ else \ * see ipng mailing list, Jun 22 2001. */ if (inp->inp_lport || - !IN6_IS_ADDR_UNSPECIFIED(&inp->inp_laddr6)) { + !IN6_IS_ADDR_UNSPECIFIED(&in6p_laddr(inp))) { error = EINVAL; break; } @@ -1563,7 +1563,7 @@ else \ error = sockopt_get(sopt, &tclass, sizeof(tclass)); if (error) break; - optp = &inp->inp_outputopts6; + optp = &in6p_outputopts(inp); error = ip6_pcbopt(optname, (u_char *)&tclass, sizeof(tclass), @@ -1581,7 +1581,7 @@ else \ break; { struct ip6_pktopts **optp; - optp = &inp->inp_outputopts6; + optp = &in6p_outputopts(inp); error = ip6_pcbopt(optname, (u_char *)&optval, sizeof(optval), @@ -1669,7 +1669,7 @@ else \ free(optbuf, M_IP6OPT); break; } - optp = &inp->inp_outputopts6; + optp = &in6p_outputopts(inp); error = ip6_pcbopt(optname, optbuf, optbuflen, optp, kauth_cred_get(), uproto); @@ -1783,7 +1783,7 @@ else \ break; case IPV6_UNICAST_HOPS: - optval = inp->inp_hops6; + optval = in6p_hops6(inp); break; case IPV6_RECVPKTINFO: @@ -1854,7 +1854,7 @@ else \ * routing, or optional information to specify * the outgoing interface. */ - sockaddr_in6_init(&u.dst6, &inp->inp_faddr6, 0, 0, 0); + sockaddr_in6_init(&u.dst6, &in6p_faddr(inp), 0, 0, 0); rt = rtcache_lookup(ro, &u.dst); error = ip6_getpmtu(rt, NULL, &pmtu, NULL); rtcache_unref(rt, ro); @@ -1910,7 +1910,7 @@ else \ case IPV6_DONTFRAG: case IPV6_USE_MIN_MTU: case IPV6_PREFER_TEMPADDR: - error = ip6_getpcbopt(inp->inp_outputopts6, + error = ip6_getpcbopt(in6p_outputopts(inp), optname, sopt); break; @@ -1994,14 +1994,14 @@ ip6_raw_ctloutput(int op, struct socket *so, struct sockopt *sopt) if (optval != icmp6off) error = EINVAL; } else - inp->inp_cksum6 = optval; + in6p_cksum(inp) = optval; break; case PRCO_GETOPT: if (so->so_proto->pr_protocol == IPPROTO_ICMPV6) optval = icmp6off; else - optval = inp->inp_cksum6; + optval = in6p_cksum(inp); error = sockopt_setint(sopt, optval); break; @@ -2429,7 +2429,7 @@ ip6_setmoptions(const struct sockopt *sopt, struct inpcb *inp) struct ipv6_mreq mreq; struct in6_addr ia; struct ifnet *ifp; - struct ip6_moptions *im6o = inp->inp_moptions6; + struct ip6_moptions *im6o = in6p_moptions(inp); struct in6_multi_mship *imm; KASSERT(inp_locked(inp)); @@ -2442,7 +2442,7 @@ ip6_setmoptions(const struct sockopt *sopt, struct inpcb *inp) im6o = malloc(sizeof(*im6o), M_IPMOPTS, M_NOWAIT); if (im6o == NULL) return (ENOBUFS); - inp->inp_moptions6 = im6o; + in6p_moptions(inp) = im6o; im6o->im6o_multicast_if_index = 0; im6o->im6o_multicast_hlim = ip6_defmcasthlim; im6o->im6o_multicast_loop = IPV6_DEFAULT_MULTICAST_LOOP; @@ -2674,8 +2674,8 @@ ip6_setmoptions(const struct sockopt *sopt, struct inpcb *inp) im6o->im6o_multicast_hlim == ip6_defmcasthlim && im6o->im6o_multicast_loop == IPV6_DEFAULT_MULTICAST_LOOP && LIST_EMPTY(&im6o->im6o_memberships)) { - free(inp->inp_moptions6, M_IPMOPTS); - inp->inp_moptions6 = NULL; + free(in6p_moptions(inp), M_IPMOPTS); + in6p_moptions(inp) = NULL; } return (error); @@ -2689,7 +2689,7 @@ ip6_getmoptions(struct sockopt *sopt, struct inpcb *inp) { u_int optval; int error; - struct ip6_moptions *im6o = inp->inp_moptions6; + struct ip6_moptions *im6o = in6p_moptions(inp); switch (sopt->sopt_name) { case IPV6_MULTICAST_IF: @@ -3302,17 +3302,17 @@ ip6_optlen(struct inpcb *inp) { int len; - if (!inp->inp_outputopts6) + if (!in6p_outputopts(inp)) return 0; len = 0; #define elen(x) \ (((struct ip6_ext *)(x)) ? (((struct ip6_ext *)(x))->ip6e_len + 1) << 3 : 0) - len += elen(inp->inp_outputopts6->ip6po_hbh); - len += elen(inp->inp_outputopts6->ip6po_dest1); - len += elen(inp->inp_outputopts6->ip6po_rthdr); - len += elen(inp->inp_outputopts6->ip6po_dest2); + len += elen(in6p_outputopts(inp)->ip6po_hbh); + len += elen(in6p_outputopts(inp)->ip6po_dest1); + len += elen(in6p_outputopts(inp)->ip6po_rthdr); + len += elen(in6p_outputopts(inp)->ip6po_dest2); return len; #undef elen } diff --git a/sys/netinet6/raw_ip6.c b/sys/netinet6/raw_ip6.c index 4abb7e5c8d4..3604445b661 100644 --- a/sys/netinet6/raw_ip6.c +++ b/sys/netinet6/raw_ip6.c @@ -191,16 +191,16 @@ rip6_input(struct mbuf **mp, int *offp, int proto) TAILQ_FOREACH(inp, &raw6cbtable.inpt_queue, inp_queue) { if (inp->inp_af != AF_INET6) continue; - if (inp->inp_ip6.ip6_nxt && - inp->inp_ip6.ip6_nxt != proto) + if (in6p_ip6(inp).ip6_nxt && + in6p_ip6(inp).ip6_nxt != proto) continue; - if (!IN6_IS_ADDR_UNSPECIFIED(&inp->inp_laddr6) && - !IN6_ARE_ADDR_EQUAL(&inp->inp_laddr6, &ip6->ip6_dst)) + if (!IN6_IS_ADDR_UNSPECIFIED(&in6p_laddr(inp)) && + !IN6_ARE_ADDR_EQUAL(&in6p_laddr(inp), &ip6->ip6_dst)) continue; - if (!IN6_IS_ADDR_UNSPECIFIED(&inp->inp_faddr6) && - !IN6_ARE_ADDR_EQUAL(&inp->inp_faddr6, &ip6->ip6_src)) + if (!IN6_IS_ADDR_UNSPECIFIED(&in6p_faddr(inp)) && + !IN6_ARE_ADDR_EQUAL(&in6p_faddr(inp), &ip6->ip6_src)) continue; - if (inp->inp_cksum6 != -1) { + if (in6p_cksum(inp) != -1) { RIP6_STATINC(RIP6_STAT_ISUM); if (in6_cksum(m, proto, *offp, m->m_pkthdr.len - *offp)) { @@ -323,8 +323,8 @@ rip6_ctlinput(int cmd, const struct sockaddr *sa, void *d) } #endif - if (inp && inp->inp_ip6.ip6_nxt && - inp->inp_ip6.ip6_nxt == nxt) + if (inp && in6p_ip6(inp).ip6_nxt && + in6p_ip6(inp).ip6_nxt == nxt) valid++; /* @@ -375,13 +375,13 @@ rip6_output(struct mbuf *m, struct socket * const so, dst = &dstsock->sin6_addr; if (control) { if ((error = ip6_setpktopts(control, &opt, - inp->inp_outputopts6, + in6p_outputopts(inp), kauth_cred_get(), so->so_proto->pr_protocol)) != 0) { goto bad; } optp = &opt; } else - optp = inp->inp_outputopts6; + optp = in6p_outputopts(inp); /* * Check and convert scope zone ID into internal form. @@ -428,8 +428,8 @@ rip6_output(struct mbuf *m, struct socket * const so, /* * Source address selection. */ - error = in6_selectsrc(dstsock, optp, inp->inp_moptions6, - &inp->inp_route, &inp->inp_laddr6, &oifp, &psref, &ip6->ip6_src); + error = in6_selectsrc(dstsock, optp, in6p_moptions(inp), + &inp->inp_route, &in6p_laddr(inp), &oifp, &psref, &ip6->ip6_src); if (error != 0) goto bad; @@ -449,18 +449,18 @@ rip6_output(struct mbuf *m, struct socket * const so, ip6->ip6_dst = dstsock->sin6_addr; /* fill in the rest of the IPv6 header fields */ - ip6->ip6_flow = inp->inp_flowinfo & IPV6_FLOWINFO_MASK; + ip6->ip6_flow = in6p_flowinfo(inp) & IPV6_FLOWINFO_MASK; ip6->ip6_vfc &= ~IPV6_VERSION_MASK; ip6->ip6_vfc |= IPV6_VERSION; /* ip6_plen will be filled in ip6_output, so not fill it here. */ - ip6->ip6_nxt = inp->inp_ip6.ip6_nxt; + ip6->ip6_nxt = in6p_ip6(inp).ip6_nxt; ip6->ip6_hlim = in6_selecthlim(inp, oifp); if_put(oifp, &psref); oifp = NULL; if (so->so_proto->pr_protocol == IPPROTO_ICMPV6 || - inp->inp_cksum6 != -1) { + in6p_cksum(inp) != -1) { const uint8_t nxt = ip6->ip6_nxt; int off; u_int16_t sum; @@ -469,7 +469,7 @@ rip6_output(struct mbuf *m, struct socket * const so, if (so->so_proto->pr_protocol == IPPROTO_ICMPV6) off = offsetof(struct icmp6_hdr, icmp6_cksum); else - off = inp->inp_cksum6; + off = in6p_cksum(inp); if (plen < off + 1) { error = EINVAL; goto bad; @@ -496,7 +496,7 @@ rip6_output(struct mbuf *m, struct socket * const so, struct ifnet *ret_oifp = NULL; error = ip6_output(m, optp, &inp->inp_route, 0, - inp->inp_moptions6, inp, &ret_oifp); + in6p_moptions(inp), inp, &ret_oifp); if (so->so_proto->pr_protocol == IPPROTO_ICMPV6) { if (ret_oifp) icmp6_ifoutstat_inc(ret_oifp, type, code); @@ -604,11 +604,11 @@ rip6_attach(struct socket *so, int proto) } splx(s); inp = sotoinpcb(so); - inp->inp_ip6.ip6_nxt = proto; - inp->inp_cksum6 = -1; + in6p_ip6(inp).ip6_nxt = proto; + in6p_cksum(inp) = -1; - inp->inp_icmp6filt = kmem_alloc(sizeof(struct icmp6_filter), KM_SLEEP); - ICMP6_FILTER_SETPASSALL(inp->inp_icmp6filt); + in6p_icmp6filt(inp) = kmem_alloc(sizeof(struct icmp6_filter), KM_SLEEP); + ICMP6_FILTER_SETPASSALL(in6p_icmp6filt(inp)); KASSERT(solocked(so)); return error; } @@ -625,9 +625,9 @@ rip6_detach(struct socket *so) ip6_mrouter_done(); } /* xxx: RSVP */ - if (inp->inp_icmp6filt != NULL) { - kmem_free(inp->inp_icmp6filt, sizeof(struct icmp6_filter)); - inp->inp_icmp6filt = NULL; + if (in6p_icmp6filt(inp) != NULL) { + kmem_free(in6p_icmp6filt(inp), sizeof(struct icmp6_filter)); + in6p_icmp6filt(inp) = NULL; } in_pcbdetach(inp); } @@ -679,7 +679,7 @@ rip6_bind(struct socket *so, struct sockaddr *nam, struct lwp *l) goto out; } - inp->inp_laddr6 = addr->sin6_addr; + in6p_laddr(inp) = addr->sin6_addr; error = 0; out: pserialize_read_exit(s); @@ -732,9 +732,9 @@ rip6_connect(struct socket *so, struct sockaddr *nam, struct lwp *l) bound = curlwp_bind(); /* Source address selection. XXX: need pcblookup? */ - error = in6_selectsrc(addr, inp->inp_outputopts6, - inp->inp_moptions6, &inp->inp_route, - &inp->inp_laddr6, &ifp, &psref, &in6a); + error = in6_selectsrc(addr, in6p_outputopts(inp), + in6p_moptions(inp), &inp->inp_route, + &in6p_laddr(inp), &ifp, &psref, &in6a); if (error != 0) goto out; /* XXX: see above */ @@ -742,8 +742,8 @@ rip6_connect(struct socket *so, struct sockaddr *nam, struct lwp *l) (error = in6_setscope(&addr->sin6_addr, ifp, NULL)) != 0) { goto out; } - inp->inp_laddr6 = in6a; - inp->inp_faddr6 = addr->sin6_addr; + in6p_laddr(inp) = in6a; + in6p_faddr(inp) = addr->sin6_addr; soisconnected(so); out: if_put(ifp, &psref); @@ -770,7 +770,7 @@ rip6_disconnect(struct socket *so) if ((so->so_state & SS_ISCONNECTED) == 0) return ENOTCONN; - inp->inp_faddr6 = in6addr_any; + in6p_faddr(inp) = in6addr_any; so->so_state &= ~SS_ISCONNECTED; /* XXX */ return 0; } @@ -875,7 +875,7 @@ rip6_send(struct socket *so, struct mbuf *m, struct sockaddr *nam, goto release; } /* XXX */ - sockaddr_in6_init(&tmp, &inp->inp_faddr6, 0, 0, 0); + sockaddr_in6_init(&tmp, &in6p_faddr(inp), 0, 0, 0); dst = &tmp; } else { if (nam == NULL) { diff --git a/sys/netinet6/sctp6_usrreq.c b/sys/netinet6/sctp6_usrreq.c index 1758b1b786d..8ee70e778c8 100644 --- a/sys/netinet6/sctp6_usrreq.c +++ b/sys/netinet6/sctp6_usrreq.c @@ -234,7 +234,7 @@ sctp_skip_csum: /* * Check AH/ESP integrity. */ - if (ipsec_used && ipsec_in_reject(m, (struct in6pcb *)in6p_ip)) { + if (ipsec_used && ipsec_in_reject(m, in6p_ip)) { /* XXX */ #if 0 /* FIX ME: need to find right stat */ @@ -262,9 +262,9 @@ sctp_skip_csum: ip6_savecontrol(in6p_ip, m, &opts, NULL); #endif #elif defined(__NetBSD__) - ip6_savecontrol((struct in6pcb *)in6p_ip, &opts, ip6, m); + ip6_savecontrol(in6p_ip, &opts, ip6, m); #else - ip6_savecontrol((struct in6pcb *)in6p_ip, m, &opts); + ip6_savecontrol(in6p_ip, m, &opts); #endif } @@ -483,8 +483,7 @@ sctp6_ctlinput(int cmd, const struct sockaddr *pktdst, void *d) } } else { if (PRC_IS_REDIRECT(cmd) && inp) { - in6_rtchange((struct in6pcb *)inp, - inet6ctlerrmap[cmd]); + in6_rtchange((struct inpcb *)inp, inet6ctlerrmap[cmd]); } if (inp) { /* reduce inp's ref-count */ diff --git a/sys/netinet6/udp6_usrreq.c b/sys/netinet6/udp6_usrreq.c index 8e5bc819e72..e1d97f45e41 100644 --- a/sys/netinet6/udp6_usrreq.c +++ b/sys/netinet6/udp6_usrreq.c @@ -474,8 +474,8 @@ udp6_realinput(int af, struct sockaddr_in6 *src, struct sockaddr_in6 *dst, if (inp->inp_lport != dport) continue; - if (!IN6_IS_ADDR_UNSPECIFIED(&inp->inp_laddr6)) { - if (!IN6_ARE_ADDR_EQUAL(&inp->inp_laddr6, + if (!IN6_IS_ADDR_UNSPECIFIED(&in6p_laddr(inp))) { + if (!IN6_ARE_ADDR_EQUAL(&in6p_laddr(inp), dst6)) continue; } else { @@ -483,8 +483,8 @@ udp6_realinput(int af, struct sockaddr_in6 *src, struct sockaddr_in6 *dst, (inp->inp_flags & IN6P_IPV6_V6ONLY)) continue; } - if (!IN6_IS_ADDR_UNSPECIFIED(&inp->inp_faddr6)) { - if (!IN6_ARE_ADDR_EQUAL(&inp->inp_faddr6, + if (!IN6_IS_ADDR_UNSPECIFIED(&in6p_faddr(inp))) { + if (!IN6_ARE_ADDR_EQUAL(&in6p_faddr(inp), &src6) || inp->inp_fport != sport) continue; } else { @@ -788,11 +788,11 @@ udp6_output(struct inpcb * const inp, struct mbuf *m, panic("%s: control but no lwp", __func__); } if ((error = ip6_setpktopts(control, &opt, - inp->inp_outputopts6, l->l_cred, IPPROTO_UDP)) != 0) + in6p_outputopts(inp), l->l_cred, IPPROTO_UDP)) != 0) goto release; optp = &opt; } else - optp = inp->inp_outputopts6; + optp = in6p_outputopts(inp); if (sin6) { @@ -808,7 +808,7 @@ udp6_output(struct inpcb * const inp, struct mbuf *m, goto release; } - if (!IN6_IS_ADDR_UNSPECIFIED(&inp->inp_faddr6)) { + if (!IN6_IS_ADDR_UNSPECIFIED(&in6p_faddr(inp))) { /* how about ::ffff:0.0.0.0 case? */ error = EISCONN; goto release; @@ -832,8 +832,8 @@ udp6_output(struct inpcb * const inp, struct mbuf *m, error = EINVAL; goto release; } - if (!IN6_IS_ADDR_UNSPECIFIED(&inp->inp_laddr6) && - !IN6_IS_ADDR_V4MAPPED(&inp->inp_laddr6)) { + if (!IN6_IS_ADDR_UNSPECIFIED(&in6p_laddr(inp)) && + !IN6_IS_ADDR_V4MAPPED(&in6p_laddr(inp))) { /* * when remote addr is an IPv4-mapped address, * local addr should not be an IPv6 address, @@ -852,9 +852,9 @@ udp6_output(struct inpcb * const inp, struct mbuf *m, int bound = curlwp_bind(); error = in6_selectsrc(sin6, optp, - inp->inp_moptions6, + in6p_moptions(inp), &inp->inp_route, - &inp->inp_laddr6, &oifp, &psref, &_laddr); + &in6p_laddr(inp), &oifp, &psref, &_laddr); if (error) laddr = NULL; else @@ -875,7 +875,7 @@ udp6_output(struct inpcb * const inp, struct mbuf *m, * udp_output() directly in this case, and thus we'll * never see this path. */ - if (IN6_IS_ADDR_UNSPECIFIED(&inp->inp_laddr6)) { + if (IN6_IS_ADDR_UNSPECIFIED(&in6p_laddr(inp))) { struct sockaddr_in sin_dst; struct in_addr ina; struct in_ifaddr *ia4; @@ -904,7 +904,7 @@ udp6_output(struct inpcb * const inp, struct mbuf *m, laddr = &laddr_mapped; } else { - laddr = &inp->inp_laddr6; /* XXX */ + laddr = &in6p_laddr(inp); /* XXX */ } } if (laddr == NULL) { @@ -928,16 +928,16 @@ udp6_output(struct inpcb * const inp, struct mbuf *m, error = in6_pcbsetport(&lsin6, inp, l); if (error) { - inp->inp_laddr6 = in6addr_any; + in6p_laddr(inp) = in6addr_any; goto release; } } } else { - if (IN6_IS_ADDR_UNSPECIFIED(&inp->inp_faddr6)) { + if (IN6_IS_ADDR_UNSPECIFIED(&in6p_faddr(inp))) { error = ENOTCONN; goto release; } - if (IN6_IS_ADDR_V4MAPPED(&inp->inp_faddr6)) { + if (IN6_IS_ADDR_V4MAPPED(&in6p_faddr(inp))) { if ((inp->inp_flags & IN6P_IPV6_V6ONLY)) { /* @@ -954,8 +954,8 @@ udp6_output(struct inpcb * const inp, struct mbuf *m, } else af = AF_INET; } - laddr = &inp->inp_laddr6; - faddr = &inp->inp_faddr6; + laddr = &in6p_laddr(inp); + faddr = &in6p_faddr(inp); fport = inp->inp_fport; } @@ -987,7 +987,7 @@ udp6_output(struct inpcb * const inp, struct mbuf *m, switch (af) { case AF_INET6: ip6 = mtod(m, struct ip6_hdr *); - ip6->ip6_flow = inp->inp_flowinfo & IPV6_FLOWINFO_MASK; + ip6->ip6_flow = in6p_flowinfo(inp) & IPV6_FLOWINFO_MASK; ip6->ip6_vfc &= ~IPV6_VERSION_MASK; ip6->ip6_vfc |= IPV6_VERSION; #if 0 /* ip6_plen will be filled in ip6_output. */ @@ -1005,7 +1005,7 @@ udp6_output(struct inpcb * const inp, struct mbuf *m, UDP6_STATINC(UDP6_STAT_OPACKETS); error = ip6_output(m, optp, &inp->inp_route, 0, - inp->inp_moptions6, inp, NULL); + in6p_moptions(inp), inp, NULL); break; case AF_INET: #ifdef INET @@ -1084,7 +1084,7 @@ udp6_attach(struct socket *so, int proto) } inp = sotoinpcb(so); - inp->inp_cksum6 = -1; /* just to be sure */ + in6p_cksum(inp) = -1; /* just to be sure */ KASSERT(solocked(so)); return 0; @@ -1147,7 +1147,7 @@ udp6_connect(struct socket *so, struct sockaddr *nam, struct lwp *l) KASSERT(solocked(so)); KASSERT(inp != NULL); - if (!IN6_IS_ADDR_UNSPECIFIED(&inp->inp_faddr6)) + if (!IN6_IS_ADDR_UNSPECIFIED(&in6p_faddr(inp))) return EISCONN; s = splsoftnet(); error = in6_pcbconnect(inp, (struct sockaddr_in6 *)nam, l); @@ -1175,12 +1175,12 @@ udp6_disconnect(struct socket *so) KASSERT(solocked(so)); KASSERT(inp != NULL); - if (IN6_IS_ADDR_UNSPECIFIED(&inp->inp_faddr6)) + if (IN6_IS_ADDR_UNSPECIFIED(&in6p_faddr(inp))) return ENOTCONN; s = splsoftnet(); in6_pcbdisconnect(inp); - memset((void *)&inp->inp_laddr6, 0, sizeof(inp->inp_laddr6)); + memset((void *)&in6p_laddr(inp), 0, sizeof(in6p_laddr(inp))); splx(s); so->so_state &= ~SS_ISCONNECTED; /* XXX */ diff --git a/usr.bin/fstat/fstat.c b/usr.bin/fstat/fstat.c index 286a38c3580..a7cd90c1108 100644 --- a/usr.bin/fstat/fstat.c +++ b/usr.bin/fstat/fstat.c @@ -1061,7 +1061,8 @@ socktrans(struct file *f, struct socket *sock, int i) struct socket so; struct protosw proto; struct domain dom; - struct inpcb inpcb; + struct in4pcb in4pcb; + struct in6pcb in6pcb; struct unpcb unpcb; struct ddpcb ddpcb; int len; @@ -1123,15 +1124,16 @@ socktrans(struct file *f, struct socket *sock, int i) case IPPROTO_TCP: if (so.so_pcb == NULL) break; - if (kvm_read(kd, (u_long)so.so_pcb, (char *)&inpcb, - sizeof(inpcb)) != sizeof(inpcb)) { - dprintf("can't read inpcb at %p", so.so_pcb); + if (kvm_read(kd, (u_long)so.so_pcb, (char *)&in4pcb, + sizeof(in4pcb)) != sizeof(in4pcb)) { + dprintf("can't read in4pcb at %p", so.so_pcb); goto bad; } - inet_addrstr(lbuf, sizeof(lbuf), &inpcb.inp_laddr, - ntohs(inpcb.inp_lport), isdgram); - inet_addrstr(fbuf, sizeof(fbuf), &inpcb.inp_faddr, - ntohs(inpcb.inp_fport), isdgram); + struct inpcb *inp = (struct inpcb *)&in4pcb; + inet_addrstr(lbuf, sizeof(lbuf), &in4p_laddr(inp), + ntohs(inp->inp_lport), isdgram); + inet_addrstr(fbuf, sizeof(fbuf), &in4p_faddr(inp), + ntohs(inp->inp_fport), isdgram); break; default: break; @@ -1147,15 +1149,16 @@ socktrans(struct file *f, struct socket *sock, int i) case IPPROTO_TCP: if (so.so_pcb == NULL) break; - if (kvm_read(kd, (u_long)so.so_pcb, (char *)&inpcb, - sizeof(inpcb)) != sizeof(inpcb)) { - dprintf("can't read inpcb at %p", so.so_pcb); + if (kvm_read(kd, (u_long)so.so_pcb, (char *)&in6pcb, + sizeof(in6pcb)) != sizeof(in6pcb)) { + dprintf("can't read in6pcb at %p", so.so_pcb); goto bad; } - inet6_addrstr(lbuf, sizeof(lbuf), &inpcb.inp_laddr6, - ntohs(inpcb.inp_lport), isdgram); - inet6_addrstr(fbuf, sizeof(fbuf), &inpcb.inp_faddr6, - ntohs(inpcb.inp_fport), isdgram); + struct inpcb *inp = (struct inpcb *)&in6pcb; + inet6_addrstr(lbuf, sizeof(lbuf), &in6p_laddr(inp), + ntohs(inp->inp_lport), isdgram); + inet6_addrstr(fbuf, sizeof(fbuf), &in6p_faddr(inp), + ntohs(inp->inp_fport), isdgram); break; default: break; diff --git a/usr.bin/netstat/inet.c b/usr.bin/netstat/inet.c index a338da3e0f6..91345b30191 100644 --- a/usr.bin/netstat/inet.c +++ b/usr.bin/netstat/inet.c @@ -276,7 +276,8 @@ getpcblist_kmem(u_long off, const char *name, size_t *len) { struct inpcbtable table; struct inpcb *next, *prev; - struct inpcb inpcb; + struct in4pcb in4pcb; + struct inpcb *inp; struct tcpcb tcpcb; struct socket sockb; int istcp = strcmp(name, "tcp") == 0; @@ -301,31 +302,32 @@ getpcblist_kmem(u_long off, const char *name, size_t *len) i = 0; while (next != TAILQ_END(head)) { - kread((u_long)next, (char *)&inpcb, sizeof inpcb); + kread((u_long)next, (char *)&in4pcb, sizeof in4pcb); prev = next; - next = TAILQ_NEXT(&inpcb, inp_queue); + inp = (struct inpcb *)&in4pcb; + next = TAILQ_NEXT(inp, inp_queue); - if (inpcb.inp_af != AF_INET) + if (inp->inp_af != AF_INET) continue; - kread((u_long)inpcb.inp_socket, (char *)&sockb, sizeof(sockb)); + kread((u_long)inp->inp_socket, (char *)&sockb, sizeof(sockb)); if (istcp) { - kread((u_long)inpcb.inp_ppcb, + kread((u_long)inp->inp_ppcb, (char *)&tcpcb, sizeof (tcpcb)); } pcblist[i].ki_ppcbaddr = - istcp ? (uintptr_t) inpcb.inp_ppcb : (uintptr_t) prev; + istcp ? (uintptr_t) inp->inp_ppcb : (uintptr_t) prev; pcblist[i].ki_rcvq = (uint64_t)sockb.so_rcv.sb_cc; pcblist[i].ki_sndq = (uint64_t)sockb.so_snd.sb_cc; - sin.sin_addr = inpcb.inp_laddr; - sin.sin_port = inpcb.inp_lport; + sin.sin_addr = in4p_laddr(inp); + sin.sin_port = inp->inp_lport; memcpy(&pcblist[i].ki_s, &sin, sizeof(sin)); - sin.sin_addr = inpcb.inp_faddr; - sin.sin_port = inpcb.inp_fport; + sin.sin_addr = in4p_faddr(inp); + sin.sin_port = inp->inp_fport; memcpy(&pcblist[i].ki_d, &sin, sizeof(sin)); pcblist[i].ki_tstate = tcpcb.t_state; - pcblist[i].ki_pflags = inpcb.inp_flags; + pcblist[i].ki_pflags = inp->inp_flags; if (i++ == size) { size += 100; if (reallocarr(&pcblist, size, sizeof(*pcblist)) != 0) diff --git a/usr.bin/netstat/inet6.c b/usr.bin/netstat/inet6.c index da69035e444..cf3a97167c1 100644 --- a/usr.bin/netstat/inet6.c +++ b/usr.bin/netstat/inet6.c @@ -141,7 +141,7 @@ extern const char * const tcptimers[]; #ifdef INET6 -struct inpcb inpcb; +struct in6pcb in6pcb; #ifdef TCP6 struct tcp6cb tcp6cb; #else @@ -288,6 +288,7 @@ getpcblist_kmem(u_long off, const char *name, size_t *len) struct socket sockb; struct inpcbtable table; struct inpcb *next, *prev; + struct inpcb *inp; int istcp = strcmp(name, "tcp6") == 0; struct kinfo_pcb *pcblist; size_t size = 100, i; @@ -309,33 +310,34 @@ getpcblist_kmem(u_long off, const char *name, size_t *len) i = 0; while (next != TAILQ_END(head)) { - kread((u_long)next, (char *)&inpcb, sizeof inpcb); - next = TAILQ_NEXT(&inpcb, inp_queue); + kread((u_long)next, (char *)&in6pcb, sizeof in6pcb); + inp = (struct inpcb *)&in6pcb; + next = TAILQ_NEXT(inp, inp_queue); prev = next; - if (inpcb.inp_af != AF_INET6) + if (inp->inp_af != AF_INET6) continue; - kread((u_long)inpcb.inp_socket, (char *)&sockb, + kread((u_long)inp->inp_socket, (char *)&sockb, sizeof (sockb)); if (istcp) { #ifdef TCP6 - kread((u_long)inpcb.inp_ppcb, + kread((u_long)inp->inp_ppcb, (char *)&tcp6cb, sizeof (tcp6cb)); #else - kread((u_long)inpcb.inp_ppcb, + kread((u_long)inp->inp_ppcb, (char *)&tcpcb, sizeof (tcpcb)); #endif } pcblist[i].ki_ppcbaddr = - istcp ? (uintptr_t) inpcb.inp_ppcb : (uintptr_t) prev; + istcp ? (uintptr_t) inp->inp_ppcb : (uintptr_t) prev; pcblist[i].ki_rcvq = (uint64_t)sockb.so_rcv.sb_cc; pcblist[i].ki_sndq = (uint64_t)sockb.so_snd.sb_cc; - sin6.sin6_addr = inpcb.inp_laddr6; - sin6.sin6_port = inpcb.inp_lport; + sin6.sin6_addr = in6p_laddr(inp); + sin6.sin6_port = inp->inp_lport; memcpy(&pcblist[i].ki_s, &sin6, sizeof(sin6)); - sin6.sin6_addr = inpcb.inp_faddr6; - sin6.sin6_port = inpcb.inp_fport; + sin6.sin6_addr = in6p_faddr(inp); + sin6.sin6_port = inp->inp_fport; memcpy(&pcblist[i].ki_d, &sin6, sizeof(sin6)); pcblist[i].ki_tstate = tcpcb.t_state; if (i++ == size) { diff --git a/usr.bin/systat/netcmds.c b/usr.bin/systat/netcmds.c index d0383a31a0b..f23d510eb85 100644 --- a/usr.bin/systat/netcmds.c +++ b/usr.bin/systat/netcmds.c @@ -331,8 +331,8 @@ checkhost(struct inpcb *inp) if (((struct sockaddr *)&p->addr)->sa_family != AF_INET) continue; s_in = (struct sockaddr_in *)&p->addr; - if (s_in->sin_addr.s_addr == inp->inp_laddr.s_addr || - s_in->sin_addr.s_addr == inp->inp_faddr.s_addr) + if (s_in->sin_addr.s_addr == in4p_laddr(inp).s_addr || + s_in->sin_addr.s_addr == in4p_faddr(inp).s_addr) return (p->onoff); } return (1); @@ -350,8 +350,8 @@ checkhost6(struct inpcb *inp) if (((struct sockaddr *)&p->addr)->sa_family != AF_INET6) continue; sin6 = (struct sockaddr_in6 *)&p->addr; - if (IN6_ARE_ADDR_EQUAL(&sin6->sin6_addr, &inp->inp_laddr6) || - IN6_ARE_ADDR_EQUAL(&sin6->sin6_addr, &inp->inp_faddr6)) + if (IN6_ARE_ADDR_EQUAL(&sin6->sin6_addr, &in6p_laddr(inp)) || + IN6_ARE_ADDR_EQUAL(&sin6->sin6_addr, &in6p_faddr(inp))) return (p->onoff); } return (1); diff --git a/usr.bin/systat/netstat.c b/usr.bin/systat/netstat.c index c05a79e0751..4c8e63f7b7f 100644 --- a/usr.bin/systat/netstat.c +++ b/usr.bin/systat/netstat.c @@ -215,7 +215,8 @@ fetchnetstat4(void *off, int istcp) struct inpcbtable pcbtable; struct inpcb **pprev, *next; struct netinfo *p; - struct inpcb inpcb, *inpcbp; + struct inpcb *inpcbp, *inp; + struct in4pcb in4pcb; struct socket sockb; struct tcpcb tcpcb; @@ -224,30 +225,31 @@ fetchnetstat4(void *off, int istcp) next = TAILQ_FIRST(&pcbtable.inpt_queue); while (next != TAILQ_END(&pcbtable.inpt_queue)) { inpcbp = (struct inpcb *)next; - KREAD(inpcbp, &inpcb, sizeof (inpcb)); - if (inpcb.inp_queue.tqe_prev != pprev) { + KREAD(inpcbp, &in4pcb, sizeof (in4pcb)); + inp = (struct inpcb *)&in4pcb; + if (inp->inp_queue.tqe_prev != pprev) { for (p = netcb.ni_forw; p != nhead; p = p->ni_forw) p->ni_seen = 1; error("Kernel state in transition"); return; } pprev = &next->inp_queue.tqe_next; - next = inpcb.inp_queue.tqe_next; + next = inp->inp_queue.tqe_next; - if (inpcb.inp_af != AF_INET) + if (inp->inp_af != AF_INET) continue; - if (!aflag && inet_lnaof(inpcb.inp_laddr) == INADDR_ANY) + if (!aflag && inet_lnaof(in4p_laddr(inp)) == INADDR_ANY) continue; - if (nhosts && !checkhost(&inpcb)) + if (nhosts && !checkhost(inp)) continue; - if (nports && !checkport(&inpcb)) + if (nports && !checkport(inp)) continue; - KREAD(inpcb.inp_socket, &sockb, sizeof (sockb)); + KREAD(inp->inp_socket, &sockb, sizeof (sockb)); if (istcp) { - KREAD(inpcb.inp_ppcb, &tcpcb, sizeof (tcpcb)); - enter(&inpcb, &sockb, tcpcb.t_state, "tcp"); + KREAD(inp->inp_ppcb, &tcpcb, sizeof (tcpcb)); + enter(inp, &sockb, tcpcb.t_state, "tcp"); } else - enter(&inpcb, &sockb, 0, "udp"); + enter(inp, &sockb, 0, "udp"); } } @@ -260,37 +262,39 @@ fetchnetstat6(void *off, int istcp) struct netinfo *p; struct socket sockb; struct tcpcb tcpcb; - struct inpcb inpcb, *inpcbp; + struct inpcb *inp, *inpcbp; + struct in6pcb in6pcb; KREAD(off, &pcbtable, sizeof pcbtable); pprev = &((struct inpcbtable *)off)->inpt_queue.tqh_first; next = TAILQ_FIRST(&pcbtable.inpt_queue); while (next != TAILQ_END(&pcbtable.inpt_queue)) { inpcbp = (struct inpcb *)next; - KREAD(inpcbp, &inpcb, sizeof (inpcb)); - if (inpcb.inp_queue.tqe_prev != pprev) { + KREAD(inpcbp, &in6pcb, sizeof (in6pcb)); + inp = (struct inpcb *)&in6pcb; + if (inp->inp_queue.tqe_prev != pprev) { for (p = netcb.ni_forw; p != nhead; p = p->ni_forw) p->ni_seen = 1; error("Kernel state in transition"); return; } pprev = &next->inp_queue.tqe_next; - next = inpcb.inp_queue.tqe_next; + next = inp->inp_queue.tqe_next; - if (inpcb.inp_af != AF_INET6) + if (inp->inp_af != AF_INET6) continue; - if (!aflag && IN6_IS_ADDR_UNSPECIFIED(&inpcb.inp_laddr6)) + if (!aflag && IN6_IS_ADDR_UNSPECIFIED(&in6p_laddr(inp))) continue; - if (nhosts && !checkhost(&inpcb)) + if (nhosts && !checkhost(inp)) continue; - if (nports && !checkport(&inpcb)) + if (nports && !checkport(inp)) continue; - KREAD(inpcb.inp_socket, &sockb, sizeof (sockb)); + KREAD(inp->inp_socket, &sockb, sizeof (sockb)); if (istcp) { - KREAD(inpcb.inp_ppcb, &tcpcb, sizeof (tcpcb)); - enter6(&inpcb, &sockb, tcpcb.t_state, "tcp"); + KREAD(inp->inp_ppcb, &tcpcb, sizeof (tcpcb)); + enter6(inp, &sockb, tcpcb.t_state, "tcp"); } else - enter6(&inpcb, &sockb, 0, "udp"); + enter6(inp, &sockb, 0, "udp"); } } #endif /*INET6*/ @@ -313,9 +317,9 @@ enter(struct inpcb *inp, struct socket *so, int state, const char *proto) if (!streq(proto, p->ni_proto)) continue; if (p->ni_lport != inp->inp_lport || - p->ni_laddr.s_addr != inp->inp_laddr.s_addr) + p->ni_laddr.s_addr != in4p_laddr(inp).s_addr) continue; - if (p->ni_faddr.s_addr == inp->inp_faddr.s_addr && + if (p->ni_faddr.s_addr == in4p_faddr(inp).s_addr && p->ni_fport == inp->inp_fport) break; } @@ -329,9 +333,9 @@ enter(struct inpcb *inp, struct socket *so, int state, const char *proto) netcb.ni_forw->ni_prev = p; netcb.ni_forw = p; p->ni_line = -1; - p->ni_laddr = inp->inp_laddr; + p->ni_laddr = in4p_laddr(inp); p->ni_lport = inp->inp_lport; - p->ni_faddr = inp->inp_faddr; + p->ni_faddr = in4p_faddr(inp); p->ni_fport = inp->inp_fport; p->ni_proto = proto; p->ni_flags = NIF_LACHG | NIF_FACHG; @@ -362,9 +366,9 @@ enter6(struct inpcb *inp, struct socket *so, int state, const char *proto) if (!streq(proto, p->ni_proto)) continue; if (p->ni_lport != inp->inp_lport || - !IN6_ARE_ADDR_EQUAL(&p->ni_laddr6, &inp->inp_laddr6)) + !IN6_ARE_ADDR_EQUAL(&p->ni_laddr6, &in6p_laddr(inp))) continue; - if (IN6_ARE_ADDR_EQUAL(&p->ni_faddr6, &inp->inp_faddr6) && + if (IN6_ARE_ADDR_EQUAL(&p->ni_faddr6, &in6p_faddr(inp)) && p->ni_fport == inp->inp_fport) break; } @@ -378,9 +382,9 @@ enter6(struct inpcb *inp, struct socket *so, int state, const char *proto) netcb.ni_forw->ni_prev = p; netcb.ni_forw = p; p->ni_line = -1; - p->ni_laddr6 = inp->inp_laddr6; + p->ni_laddr6 = in6p_laddr(inp); p->ni_lport = inp->inp_lport; - p->ni_faddr6 = inp->inp_faddr6; + p->ni_faddr6 = in6p_faddr(inp); p->ni_fport = inp->inp_fport; p->ni_proto = proto; p->ni_flags = NIF_LACHG | NIF_FACHG;