summaryrefslogtreecommitdiffstats
path: root/sys/netinet
diff options
context:
space:
mode:
authorbz <bz@FreeBSD.org>2008-12-17 12:52:34 +0000
committerbz <bz@FreeBSD.org>2008-12-17 12:52:34 +0000
commitea0d9d2e9af995a203d1871d5aded293a98f5d68 (patch)
tree062997817526e8ebb92f0a727bd3ebf774556ea8 /sys/netinet
parentbaed8aaae54e47b5ef994a307febc994595b0e50 (diff)
downloadFreeBSD-src-ea0d9d2e9af995a203d1871d5aded293a98f5d68.zip
FreeBSD-src-ea0d9d2e9af995a203d1871d5aded293a98f5d68.tar.gz
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
Diffstat (limited to 'sys/netinet')
-rw-r--r--sys/netinet/in_pcb.c2
-rw-r--r--sys/netinet/in_pcb.h6
-rw-r--r--sys/netinet/tcp_hostcache.c8
-rw-r--r--sys/netinet/tcp_input.c7
-rw-r--r--sys/netinet/tcp_subr.c10
-rw-r--r--sys/netinet/tcp_syncache.c31
-rw-r--r--sys/netinet/tcp_timewait.c2
-rw-r--r--sys/netinet/tcp_usrreq.c2
8 files changed, 35 insertions, 33 deletions
diff --git a/sys/netinet/in_pcb.c b/sys/netinet/in_pcb.c
index 84bff92..6d1c2aa 100644
--- a/sys/netinet/in_pcb.c
+++ b/sys/netinet/in_pcb.c
@@ -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);
diff --git a/sys/netinet/in_pcb.h b/sys/netinet/in_pcb.h
index f0275bd..0862c95 100644
--- a/sys/netinet/in_pcb.h
+++ b/sys/netinet/in_pcb.h
@@ -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
diff --git a/sys/netinet/tcp_hostcache.c b/sys/netinet/tcp_hostcache.c
index 7c76160..c9b5b8c 100644
--- a/sys/netinet/tcp_hostcache.c
+++ b/sys/netinet/tcp_hostcache.c
@@ -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;
diff --git a/sys/netinet/tcp_input.c b/sys/netinet/tcp_input.c
index dfb2aff..30b3fde 100644
--- a/sys/netinet/tcp_input.c
+++ b/sys/netinet/tcp_input.c
@@ -737,9 +737,9 @@ findpcb:
"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 */
diff --git a/sys/netinet/tcp_subr.c b/sys/netinet/tcp_subr.c
index 2c22132..9cb941a 100644
--- a/sys/netinet/tcp_subr.c
+++ b/sys/netinet/tcp_subr.c
@@ -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));
diff --git a/sys/netinet/tcp_syncache.c b/sys/netinet/tcp_syncache.c
index 0d1511a..18fab28 100644
--- a/sys/netinet/tcp_syncache.c
+++ b/sys/netinet/tcp_syncache.c
@@ -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;
diff --git a/sys/netinet/tcp_timewait.c b/sys/netinet/tcp_timewait.c
index 37fafa0..3138547 100644
--- a/sys/netinet/tcp_timewait.c
+++ b/sys/netinet/tcp_timewait.c
@@ -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);
diff --git a/sys/netinet/tcp_usrreq.c b/sys/netinet/tcp_usrreq.c
index 52ed34b..f6dcae1 100644
--- a/sys/netinet/tcp_usrreq.c
+++ b/sys/netinet/tcp_usrreq.c
@@ -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;
OpenPOWER on IntegriCloud