Use inc_flags instead of the inc_isipv6 alias which so far
had been the only flag with random usage patterns. Switch inc_flags to be used as a real bit field by using INC_ISIPV6 with bitops to check for the 'isipv6' condition. While here fix a place or two where in case of v4 inc_flags were not properly initialized before.[1] Found by: rwatson during review [1] Discussed with: rwatson Reviewed by: rwatson MFC after: 4 weeks
This commit is contained in:
parent
1fa9ee7d60
commit
dcdb4371ca
@ -3269,8 +3269,6 @@ syncache_add_accept_req(struct cpl_pass_accept_req *req, struct socket *lso, str
|
||||
|
||||
toep->tp_iss = toep->tp_delack_seq = toep->tp_rcv_wup = toep->tp_copied_seq = rcv_isn + 1;
|
||||
|
||||
|
||||
inc.inc_isipv6 = 0;
|
||||
inc.inc_len = 0;
|
||||
inc.inc_faddr.s_addr = req->peer_ip;
|
||||
inc.inc_laddr.s_addr = req->local_ip;
|
||||
@ -3610,7 +3608,6 @@ syncache_expand_establish_req(struct cpl_pass_establish *req, struct socket **so
|
||||
th.th_seq = req->rcv_isn;
|
||||
th.th_flags = TH_ACK;
|
||||
|
||||
inc.inc_isipv6 = 0;
|
||||
inc.inc_len = 0;
|
||||
inc.inc_faddr.s_addr = req->peer_ip;
|
||||
inc.inc_laddr.s_addr = req->local_ip;
|
||||
|
@ -1700,7 +1700,7 @@ db_print_inconninfo(struct in_conninfo *inc, const char *name, int indent)
|
||||
indent += 2;
|
||||
|
||||
#ifdef INET6
|
||||
if (inc->inc_flags == 1) {
|
||||
if (inc->inc_flags & INC_ISIPV6) {
|
||||
/* IPv6. */
|
||||
ip6_sprintf(laddr_str, &inc->inc6_laddr);
|
||||
ip6_sprintf(faddr_str, &inc->inc6_faddr);
|
||||
|
@ -106,6 +106,12 @@ struct in_conninfo {
|
||||
/* protocol dependent part */
|
||||
struct in_endpoints inc_ie;
|
||||
};
|
||||
|
||||
/*
|
||||
* Flags for inc_flags.
|
||||
*/
|
||||
#define INC_ISIPV6 0x01
|
||||
|
||||
#define inc_isipv6 inc_flags /* temp compatability */
|
||||
#define inc_fport inc_ie.ie_fport
|
||||
#define inc_lport inc_ie.ie_lport
|
||||
|
@ -249,7 +249,7 @@ tcp_hc_lookup(struct in_conninfo *inc)
|
||||
/*
|
||||
* Hash the foreign ip address.
|
||||
*/
|
||||
if (inc->inc_isipv6)
|
||||
if (inc->inc_flags & INC_ISIPV6)
|
||||
hash = HOSTCACHE_HASH6(&inc->inc6_faddr);
|
||||
else
|
||||
hash = HOSTCACHE_HASH(&inc->inc_faddr);
|
||||
@ -267,7 +267,7 @@ tcp_hc_lookup(struct in_conninfo *inc)
|
||||
* Iterate through entries in bucket row looking for a match.
|
||||
*/
|
||||
TAILQ_FOREACH(hc_entry, &hc_head->hch_bucket, rmx_q) {
|
||||
if (inc->inc_isipv6) {
|
||||
if (inc->inc_flags & INC_ISIPV6) {
|
||||
if (memcmp(&inc->inc6_faddr, &hc_entry->ip6,
|
||||
sizeof(inc->inc6_faddr)) == 0)
|
||||
return hc_entry;
|
||||
@ -305,7 +305,7 @@ tcp_hc_insert(struct in_conninfo *inc)
|
||||
/*
|
||||
* Hash the foreign ip address.
|
||||
*/
|
||||
if (inc->inc_isipv6)
|
||||
if (inc->inc_flags & INC_ISIPV6)
|
||||
hash = HOSTCACHE_HASH6(&inc->inc6_faddr);
|
||||
else
|
||||
hash = HOSTCACHE_HASH(&inc->inc_faddr);
|
||||
@ -360,7 +360,7 @@ tcp_hc_insert(struct in_conninfo *inc)
|
||||
* Initialize basic information of hostcache entry.
|
||||
*/
|
||||
bzero(hc_entry, sizeof(*hc_entry));
|
||||
if (inc->inc_isipv6)
|
||||
if (inc->inc_flags & INC_ISIPV6)
|
||||
bcopy(&inc->inc6_faddr, &hc_entry->ip6, sizeof(hc_entry->ip6));
|
||||
else
|
||||
hc_entry->ip4 = inc->inc_faddr;
|
||||
|
@ -737,9 +737,9 @@ tcp_input(struct mbuf *m, int off0)
|
||||
"tp not listening", __func__));
|
||||
|
||||
bzero(&inc, sizeof(inc));
|
||||
inc.inc_isipv6 = isipv6;
|
||||
#ifdef INET6
|
||||
if (isipv6) {
|
||||
inc.inc_flags |= INC_ISIPV6;
|
||||
inc.inc6_faddr = ip6->ip6_src;
|
||||
inc.inc6_laddr = ip6->ip6_dst;
|
||||
} else
|
||||
@ -3338,14 +3338,11 @@ tcp_mssopt(struct in_conninfo *inc)
|
||||
u_long maxmtu = 0;
|
||||
u_long thcmtu = 0;
|
||||
size_t min_protoh;
|
||||
#ifdef INET6
|
||||
int isipv6 = inc->inc_isipv6 ? 1 : 0;
|
||||
#endif
|
||||
|
||||
KASSERT(inc != NULL, ("tcp_mssopt with NULL in_conninfo pointer"));
|
||||
|
||||
#ifdef INET6
|
||||
if (isipv6) {
|
||||
if (inc->inc_flags & INC_ISIPV6) {
|
||||
mss = V_tcp_v6mssdflt;
|
||||
maxmtu = tcp_maxmtu6(inc, NULL);
|
||||
thcmtu = tcp_hc_getmtu(inc); /* IPv4 and IPv6 */
|
||||
|
@ -1306,7 +1306,6 @@ tcp_ctlinput(int cmd, struct sockaddr *sa, void *vip)
|
||||
* value (if given) and then notify.
|
||||
*/
|
||||
bzero(&inc, sizeof(inc));
|
||||
inc.inc_flags = 0; /* IPv4 */
|
||||
inc.inc_faddr = faddr;
|
||||
inc.inc_fibnum =
|
||||
inp->inp_inc.inc_fibnum;
|
||||
@ -1343,13 +1342,11 @@ tcp_ctlinput(int cmd, struct sockaddr *sa, void *vip)
|
||||
if (inp != NULL)
|
||||
INP_WUNLOCK(inp);
|
||||
} else {
|
||||
bzero(&inc, sizeof(inc));
|
||||
inc.inc_fport = th->th_dport;
|
||||
inc.inc_lport = th->th_sport;
|
||||
inc.inc_faddr = faddr;
|
||||
inc.inc_laddr = ip->ip_src;
|
||||
#ifdef INET6
|
||||
inc.inc_isipv6 = 0;
|
||||
#endif
|
||||
syncache_unreach(&inc, th);
|
||||
}
|
||||
INP_INFO_WUNLOCK(&V_tcbinfo);
|
||||
@ -1419,11 +1416,12 @@ tcp6_ctlinput(int cmd, struct sockaddr *sa, void *d)
|
||||
(struct sockaddr *)ip6cp->ip6c_src,
|
||||
th.th_sport, cmd, NULL, notify);
|
||||
|
||||
bzero(&inc, sizeof(inc));
|
||||
inc.inc_fport = th.th_dport;
|
||||
inc.inc_lport = th.th_sport;
|
||||
inc.inc6_faddr = ((struct sockaddr_in6 *)sa)->sin6_addr;
|
||||
inc.inc6_laddr = ip6cp->ip6c_src->sin6_addr;
|
||||
inc.inc_isipv6 = 1;
|
||||
inc.inc_flags |= INC_ISIPV6;
|
||||
INP_INFO_WLOCK(&V_tcbinfo);
|
||||
syncache_unreach(&inc, &th);
|
||||
INP_INFO_WUNLOCK(&V_tcbinfo);
|
||||
@ -2263,7 +2261,7 @@ tcp_log_addrs(struct in_conninfo *inc, struct tcphdr *th, void *ip4hdr,
|
||||
strcat(s, "TCP: [");
|
||||
sp = s + strlen(s);
|
||||
|
||||
if (inc && inc->inc_isipv6 == 0) {
|
||||
if (inc && ((inc->inc_flags & INC_ISIPV6) == 0)) {
|
||||
inet_ntoa_r(inc->inc_faddr, sp);
|
||||
sp = s + strlen(s);
|
||||
sprintf(sp, "]:%i to [", ntohs(inc->inc_fport));
|
||||
|
@ -430,7 +430,7 @@ syncache_lookup(struct in_conninfo *inc, struct syncache_head **schp)
|
||||
struct syncache_head *sch;
|
||||
|
||||
#ifdef INET6
|
||||
if (inc->inc_isipv6) {
|
||||
if (inc->inc_flags & INC_ISIPV6) {
|
||||
sch = &V_tcp_syncache.hashbase[
|
||||
SYNCACHE_HASH6(inc, V_tcp_syncache.hashmask)];
|
||||
*schp = sch;
|
||||
@ -454,7 +454,7 @@ syncache_lookup(struct in_conninfo *inc, struct syncache_head **schp)
|
||||
/* Circle through bucket row to find matching entry. */
|
||||
TAILQ_FOREACH(sc, &sch->sch_bucket, sc_hash) {
|
||||
#ifdef INET6
|
||||
if (sc->sc_inc.inc_isipv6)
|
||||
if (sc->sc_inc.inc_flags & INC_ISIPV6)
|
||||
continue;
|
||||
#endif
|
||||
if (ENDPTS_EQ(&inc->inc_ie, &sc->sc_inc.inc_ie))
|
||||
@ -643,9 +643,9 @@ syncache_socket(struct syncache *sc, struct socket *lso, struct mbuf *m)
|
||||
INP_WLOCK(inp);
|
||||
|
||||
/* Insert new socket into PCB hash list. */
|
||||
inp->inp_inc.inc_isipv6 = sc->sc_inc.inc_isipv6;
|
||||
inp->inp_inc.inc_flags = sc->sc_inc.inc_flags;
|
||||
#ifdef INET6
|
||||
if (sc->sc_inc.inc_isipv6) {
|
||||
if (sc->sc_inc.inc_flags & INC_ISIPV6) {
|
||||
inp->in6p_laddr = sc->sc_inc.inc6_laddr;
|
||||
} else {
|
||||
inp->inp_vflag &= ~INP_IPV6;
|
||||
@ -662,7 +662,7 @@ syncache_socket(struct syncache *sc, struct socket *lso, struct mbuf *m)
|
||||
* put the PCB on the hash lists.
|
||||
*/
|
||||
#ifdef INET6
|
||||
if (sc->sc_inc.inc_isipv6)
|
||||
if (sc->sc_inc.inc_flags & INC_ISIPV6)
|
||||
inp->in6p_laddr = in6addr_any;
|
||||
else
|
||||
#endif
|
||||
@ -676,7 +676,7 @@ syncache_socket(struct syncache *sc, struct socket *lso, struct mbuf *m)
|
||||
printf("syncache_socket: could not copy policy\n");
|
||||
#endif
|
||||
#ifdef INET6
|
||||
if (sc->sc_inc.inc_isipv6) {
|
||||
if (sc->sc_inc.inc_flags & INC_ISIPV6) {
|
||||
struct inpcb *oinp = sotoinpcb(lso);
|
||||
struct in6_addr laddr6;
|
||||
struct sockaddr_in6 sin6;
|
||||
@ -993,7 +993,7 @@ _syncache_add(struct in_conninfo *inc, struct tcpopt *to, struct tcphdr *th,
|
||||
cred = crhold(so->so_cred);
|
||||
|
||||
#ifdef INET6
|
||||
if (inc->inc_isipv6 &&
|
||||
if ((inc->inc_flags & INC_ISIPV6) &&
|
||||
(inp->inp_flags & IN6P_AUTOFLOWLABEL))
|
||||
autoflowlabel = 1;
|
||||
#endif
|
||||
@ -1022,7 +1022,7 @@ _syncache_add(struct in_conninfo *inc, struct tcpopt *to, struct tcphdr *th,
|
||||
* Remember the IP options, if any.
|
||||
*/
|
||||
#ifdef INET6
|
||||
if (!inc->inc_isipv6)
|
||||
if (!(inc->inc_flags & INC_ISIPV6))
|
||||
#endif
|
||||
ipopts = (m) ? ip_srcroute(m) : NULL;
|
||||
|
||||
@ -1123,10 +1123,11 @@ _syncache_add(struct in_conninfo *inc, struct tcpopt *to, struct tcphdr *th,
|
||||
sc->sc_cred = cred;
|
||||
cred = NULL;
|
||||
sc->sc_ipopts = ipopts;
|
||||
/* XXX-BZ this fib assignment is just useless. */
|
||||
sc->sc_inc.inc_fibnum = inp->inp_inc.inc_fibnum;
|
||||
bcopy(inc, &sc->sc_inc, sizeof(struct in_conninfo));
|
||||
#ifdef INET6
|
||||
if (!inc->inc_isipv6)
|
||||
if (!(inc->inc_flags & INC_ISIPV6))
|
||||
#endif
|
||||
{
|
||||
sc->sc_ip_tos = ip_tos;
|
||||
@ -1272,7 +1273,7 @@ syncache_respond(struct syncache *sc)
|
||||
|
||||
hlen =
|
||||
#ifdef INET6
|
||||
(sc->sc_inc.inc_isipv6) ? sizeof(struct ip6_hdr) :
|
||||
(sc->sc_inc.inc_flags & INC_ISIPV6) ? sizeof(struct ip6_hdr) :
|
||||
#endif
|
||||
sizeof(struct ip);
|
||||
tlen = hlen + sizeof(struct tcphdr);
|
||||
@ -1299,7 +1300,7 @@ syncache_respond(struct syncache *sc)
|
||||
m->m_pkthdr.rcvif = NULL;
|
||||
|
||||
#ifdef INET6
|
||||
if (sc->sc_inc.inc_isipv6) {
|
||||
if (sc->sc_inc.inc_flags & INC_ISIPV6) {
|
||||
ip6 = mtod(m, struct ip6_hdr *);
|
||||
ip6->ip6_vfc = IPV6_VERSION;
|
||||
ip6->ip6_nxt = IPPROTO_TCP;
|
||||
@ -1390,7 +1391,7 @@ syncache_respond(struct syncache *sc)
|
||||
to.to_signature, IPSEC_DIR_OUTBOUND);
|
||||
#endif
|
||||
#ifdef INET6
|
||||
if (sc->sc_inc.inc_isipv6)
|
||||
if (sc->sc_inc.inc_flags & INC_ISIPV6)
|
||||
ip6->ip6_plen = htons(ntohs(ip6->ip6_plen) + optlen);
|
||||
else
|
||||
#endif
|
||||
@ -1399,7 +1400,7 @@ syncache_respond(struct syncache *sc)
|
||||
optlen = 0;
|
||||
|
||||
#ifdef INET6
|
||||
if (sc->sc_inc.inc_isipv6) {
|
||||
if (sc->sc_inc.inc_flags & INC_ISIPV6) {
|
||||
th->th_sum = 0;
|
||||
th->th_sum = in6_cksum(m, IPPROTO_TCP, hlen,
|
||||
tlen + optlen - hlen);
|
||||
@ -1653,7 +1654,7 @@ syncookie_lookup(struct in_conninfo *inc, struct syncache_head *sch,
|
||||
sc->sc_iss = ack;
|
||||
|
||||
#ifdef INET6
|
||||
if (inc->inc_isipv6) {
|
||||
if (inc->inc_flags & INC_ISIPV6) {
|
||||
if (sotoinpcb(so)->inp_flags & IN6P_AUTOFLOWLABEL)
|
||||
sc->sc_flowlabel = md5_buffer[1] & IPV6_FLOWLABEL_MASK;
|
||||
} else
|
||||
@ -1743,7 +1744,7 @@ syncache_pcblist(struct sysctl_req *req, int max_pcbs, int *pcbs_exported)
|
||||
continue;
|
||||
bzero(&xt, sizeof(xt));
|
||||
xt.xt_len = sizeof(xt);
|
||||
if (sc->sc_inc.inc_isipv6)
|
||||
if (sc->sc_inc.inc_flags & INC_ISIPV6)
|
||||
xt.xt_inp.inp_vflag = INP_IPV6;
|
||||
else
|
||||
xt.xt_inp.inp_vflag = INP_IPV4;
|
||||
|
@ -538,7 +538,7 @@ tcp_twrespond(struct tcptw *tw, int flags)
|
||||
struct tcpopt to;
|
||||
#ifdef INET6
|
||||
struct ip6_hdr *ip6 = NULL;
|
||||
int isipv6 = inp->inp_inc.inc_isipv6;
|
||||
int isipv6 = inp->inp_inc.inc_flags & INC_ISIPV6;
|
||||
#endif
|
||||
|
||||
INP_WLOCK_ASSERT(inp);
|
||||
|
@ -519,7 +519,7 @@ tcp6_usr_connect(struct socket *so, struct sockaddr *nam, struct thread *td)
|
||||
}
|
||||
inp->inp_vflag &= ~INP_IPV4;
|
||||
inp->inp_vflag |= INP_IPV6;
|
||||
inp->inp_inc.inc_isipv6 = 1;
|
||||
inp->inp_inc.inc_flags |= INC_ISIPV6;
|
||||
if (prison_remote_ip6(td->td_ucred, &sin6p->sin6_addr) != 0) {
|
||||
error = EINVAL;
|
||||
goto out;
|
||||
|
@ -1148,7 +1148,7 @@ icmp6_mtudisc_update(struct ip6ctlparam *ip6cp, int validated)
|
||||
mtu = IPV6_MMTU - 8;
|
||||
|
||||
bzero(&inc, sizeof(inc));
|
||||
inc.inc_flags = 1; /* IPv6 */
|
||||
inc.inc_flags |= INC_ISIPV6;
|
||||
inc.inc6_faddr = *dst;
|
||||
if (in6_setscope(&inc.inc6_faddr, m->m_pkthdr.rcvif, NULL))
|
||||
return;
|
||||
|
@ -1320,7 +1320,7 @@ ip6_getpmtu(struct route_in6 *ro_pmtu, struct route_in6 *ro,
|
||||
struct in_conninfo inc;
|
||||
|
||||
bzero(&inc, sizeof(inc));
|
||||
inc.inc_flags = 1; /* IPv6 */
|
||||
inc.inc_flags |= INC_ISIPV6;
|
||||
inc.inc6_faddr = *dst;
|
||||
|
||||
if (ifp == NULL)
|
||||
|
Loading…
Reference in New Issue
Block a user