aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBjoern A. Zeeb <bz@FreeBSD.org>2011-04-30 11:21:29 +0000
committerBjoern A. Zeeb <bz@FreeBSD.org>2011-04-30 11:21:29 +0000
commitb287c6c70cd41c6805ade3f16b073028c5ccd836 (patch)
tree323517c1065faea8844fb601613c16c72f091e61
parente6194c2ed4c3fe69ba25a005d1b8b387d1ce982f (diff)
downloadsrc-b287c6c70cd41c6805ade3f16b073028c5ccd836.tar.gz
src-b287c6c70cd41c6805ade3f16b073028c5ccd836.zip
Make the TCP code compile without INET. Sort #includes and add #ifdef INETs.
Add some comments at #endifs given more nestedness. To make the compiler happy, some default initializations were added in accordance with the style on the files. Reviewed by: gnn Sponsored by: The FreeBSD Foundation Sponsored by: iXsystems MFC after: 4 days
Notes
Notes: svn path=/head/; revision=221250
-rw-r--r--sys/conf/files28
-rw-r--r--sys/netinet/tcp_input.c110
-rw-r--r--sys/netinet/tcp_output.c15
-rw-r--r--sys/netinet/tcp_subr.c79
-rw-r--r--sys/netinet/tcp_syncache.c29
-rw-r--r--sys/netinet/tcp_timewait.c62
-rw-r--r--sys/netinet/tcp_usrreq.c52
7 files changed, 278 insertions, 97 deletions
diff --git a/sys/conf/files b/sys/conf/files
index 191238921ed3..1f86b6641912 100644
--- a/sys/conf/files
+++ b/sys/conf/files
@@ -2740,8 +2740,8 @@ netinet/ip_mroute.c optional mrouting inet | mrouting inet6
netinet/ip_options.c optional inet
netinet/ip_output.c optional inet
netinet/raw_ip.c optional inet
-netinet/cc/cc.c optional inet
-netinet/cc/cc_newreno.c optional inet
+netinet/cc/cc.c optional inet | inet6
+netinet/cc/cc_newreno.c optional inet | inet6
netinet/sctp_asconf.c optional inet sctp
netinet/sctp_auth.c optional inet sctp
netinet/sctp_bsd_addr.c optional inet sctp
@@ -2758,18 +2758,18 @@ netinet/sctp_timer.c optional inet sctp
netinet/sctp_usrreq.c optional inet sctp
netinet/sctputil.c optional inet sctp
netinet/tcp_debug.c optional tcpdebug
-netinet/tcp_hostcache.c optional inet
-netinet/tcp_input.c optional inet
-netinet/tcp_lro.c optional inet
-netinet/tcp_output.c optional inet
-netinet/tcp_offload.c optional inet
-netinet/tcp_reass.c optional inet
-netinet/tcp_sack.c optional inet
-netinet/tcp_subr.c optional inet
-netinet/tcp_syncache.c optional inet
-netinet/tcp_timer.c optional inet
-netinet/tcp_timewait.c optional inet
-netinet/tcp_usrreq.c optional inet
+netinet/tcp_hostcache.c optional inet | inet6
+netinet/tcp_input.c optional inet | inet6
+netinet/tcp_lro.c optional inet | inet6
+netinet/tcp_output.c optional inet | inet6
+netinet/tcp_offload.c optional inet | inet6
+netinet/tcp_reass.c optional inet | inet6
+netinet/tcp_sack.c optional inet | inet6
+netinet/tcp_subr.c optional inet | inet6
+netinet/tcp_syncache.c optional inet | inet6
+netinet/tcp_timer.c optional inet | inet6
+netinet/tcp_timewait.c optional inet | inet6
+netinet/tcp_usrreq.c optional inet | inet6
netinet/udp_usrreq.c optional inet | inet6
netinet/libalias/alias.c optional libalias inet | netgraph_nat inet
netinet/libalias/alias_db.c optional libalias inet | netgraph_nat inet
diff --git a/sys/netinet/tcp_input.c b/sys/netinet/tcp_input.c
index 30e84296afec..70c1522680e8 100644
--- a/sys/netinet/tcp_input.c
+++ b/sys/netinet/tcp_input.c
@@ -367,12 +367,13 @@ cc_conn_init(struct tcpcb *tp)
tp->snd_cwnd = min(4 * tp->t_maxseg,
max(2 * tp->t_maxseg, 4380));
#ifdef INET6
- else if ((isipv6 && in6_localaddr(&inp->in6p_faddr)) ||
- (!isipv6 && in_localaddr(inp->inp_faddr)))
-#else
- else if (in_localaddr(inp->inp_faddr))
+ else if (isipv6 && in6_localaddr(&inp->in6p_faddr))
+ tp->snd_cwnd = tp->t_maxseg * V_ss_fltsz_local;
#endif
+#if defined(INET) || defined(INET6)
+ else if (in_localaddr(inp->inp_faddr))
tp->snd_cwnd = tp->t_maxseg * V_ss_fltsz_local;
+#endif
else
tp->snd_cwnd = tp->t_maxseg * V_ss_fltsz;
@@ -542,37 +543,46 @@ tcp6_input(struct mbuf **mp, int *offp, int proto)
tcp_input(m, *offp);
return IPPROTO_DONE;
}
-#endif
+#endif /* INET6 */
void
tcp_input(struct mbuf *m, int off0)
{
- struct tcphdr *th;
+ struct tcphdr *th = NULL;
struct ip *ip = NULL;
+#ifdef INET
struct ipovly *ipov;
+#endif
struct inpcb *inp = NULL;
struct tcpcb *tp = NULL;
struct socket *so = NULL;
u_char *optp = NULL;
int optlen = 0;
- int len, tlen, off;
+#ifdef INET
+ int len;
+#endif
+ int tlen = 0, off;
int drop_hdrlen;
int thflags;
int rstreason = 0; /* For badport_bandlim accounting purposes */
- uint8_t iptos;
#ifdef TCP_SIGNATURE
uint8_t sig_checked = 0;
#endif
+ uint8_t iptos = 0;
+#ifdef INET
#ifdef IPFIREWALL_FORWARD
struct m_tag *fwd_tag;
#endif
+#endif /* INET */
#ifdef INET6
struct ip6_hdr *ip6 = NULL;
int isipv6;
#else
const void *ip6 = NULL;
+#if (defined(INET) && defined(IPFIREWALL_FORWARD)) || defined(TCPDEBUG)
const int isipv6 = 0;
#endif
+#endif /* INET6 */
struct tcpopt to; /* options in this segment */
char *s = NULL; /* address and port logging */
int ti_locked;
@@ -597,8 +607,8 @@ tcp_input(struct mbuf *m, int off0)
to.to_flags = 0;
TCPSTAT_INC(tcps_rcvtotal);
- if (isipv6) {
#ifdef INET6
+ if (isipv6) {
/* IP6_EXTHDR_CHECK() is already done at tcp6_input(). */
ip6 = mtod(m, struct ip6_hdr *);
tlen = sizeof(*ip6) + ntohs(ip6->ip6_plen) - off0;
@@ -620,10 +630,13 @@ tcp_input(struct mbuf *m, int off0)
/* XXX stat */
goto drop;
}
-#else
- th = NULL; /* XXX: Avoid compiler warning. */
+ }
#endif
- } else {
+#if defined(INET) && defined(INET6)
+ else
+#endif
+#ifdef INET
+ {
/*
* Get IP and TCP header together in first mbuf.
* Note: IP leaves IP header in first mbuf.
@@ -675,13 +688,18 @@ tcp_input(struct mbuf *m, int off0)
/* Re-initialization for later version check */
ip->ip_v = IPVERSION;
}
+#endif /* INET */
#ifdef INET6
if (isipv6)
iptos = (ntohl(ip6->ip6_flow) >> 20) & 0xff;
+#endif
+#if defined(INET) && defined(INET6)
else
#endif
+#ifdef INET
iptos = ip->ip_tos;
+#endif
/*
* Check that TCP offset makes sense,
@@ -694,13 +712,18 @@ tcp_input(struct mbuf *m, int off0)
}
tlen -= off; /* tlen is used instead of ti->ti_len */
if (off > sizeof (struct tcphdr)) {
- if (isipv6) {
#ifdef INET6
+ if (isipv6) {
IP6_EXTHDR_CHECK(m, off0, off, );
ip6 = mtod(m, struct ip6_hdr *);
th = (struct tcphdr *)((caddr_t)ip6 + off0);
+ }
#endif
- } else {
+#if defined(INET) && defined(INET6)
+ else
+#endif
+#ifdef INET
+ {
if (m->m_len < sizeof(struct ip) + off) {
if ((m = m_pullup(m, sizeof (struct ip) + off))
== NULL) {
@@ -712,6 +735,7 @@ tcp_input(struct mbuf *m, int off0)
th = (struct tcphdr *)((caddr_t)ip + off0);
}
}
+#endif
optlen = off - sizeof (struct tcphdr);
optp = (u_char *)(th + 1);
}
@@ -754,6 +778,7 @@ findpcb:
panic("%s: findpcb ti_locked %d\n", __func__, ti_locked);
#endif
+#ifdef INET
#ifdef IPFIREWALL_FORWARD
/*
* Grab info from PACKET_TAG_IPFORWARD tag prepended to the chain.
@@ -787,21 +812,26 @@ findpcb:
m_tag_delete(m, fwd_tag);
} else
#endif /* IPFIREWALL_FORWARD */
+#endif /* INET */
{
- if (isipv6) {
#ifdef INET6
+ if (isipv6)
inp = in6_pcblookup_hash(&V_tcbinfo,
&ip6->ip6_src, th->th_sport,
&ip6->ip6_dst, th->th_dport,
INPLOOKUP_WILDCARD,
m->m_pkthdr.rcvif);
#endif
- } else
+#if defined(INET) && defined(INET6)
+ else
+#endif
+#ifdef INET
inp = in_pcblookup_hash(&V_tcbinfo,
ip->ip_src, th->th_sport,
ip->ip_dst, th->th_dport,
INPLOOKUP_WILDCARD,
m->m_pkthdr.rcvif);
+#endif
}
/*
@@ -989,7 +1019,7 @@ relocked:
bcopy((char *)ip, (char *)tcp_saveipgen, sizeof(*ip));
tcp_savetcp = *th;
}
-#endif
+#endif /* TCPDEBUG */
/*
* When the socket is accepting connections (the INPCB is in LISTEN
* state) we look into the SYN cache if this is a new connection
@@ -1224,7 +1254,7 @@ relocked:
}
ifa_free(&ia6->ia_ifa);
}
-#endif
+#endif /* INET6 */
/*
* Basic sanity checks on incoming SYN requests:
* Don't respond if the destination is a link layer
@@ -1243,8 +1273,8 @@ relocked:
"link layer address ignored\n", s, __func__);
goto dropunlock;
}
- if (isipv6) {
#ifdef INET6
+ if (isipv6) {
if (th->th_dport == th->th_sport &&
IN6_ARE_ADDR_EQUAL(&ip6->ip6_dst, &ip6->ip6_src)) {
if ((s = tcp_log_addrs(&inc, th, NULL, NULL)))
@@ -1261,8 +1291,13 @@ relocked:
"address ignored\n", s, __func__);
goto dropunlock;
}
+ }
#endif
- } else {
+#if defined(INET) && defined(INET6)
+ else
+#endif
+#ifdef INET
+ {
if (th->th_dport == th->th_sport &&
ip->ip_dst.s_addr == ip->ip_src.s_addr) {
if ((s = tcp_log_addrs(&inc, th, NULL, NULL)))
@@ -1283,6 +1318,7 @@ relocked:
goto dropunlock;
}
}
+#endif
/*
* SYN appears to be valid. Create compressed TCP state
* for syncache.
@@ -3020,7 +3056,9 @@ static void
tcp_dropwithreset(struct mbuf *m, struct tcphdr *th, struct tcpcb *tp,
int tlen, int rstreason)
{
+#ifdef INET
struct ip *ip;
+#endif
#ifdef INET6
struct ip6_hdr *ip6;
#endif
@@ -3039,8 +3077,12 @@ tcp_dropwithreset(struct mbuf *m, struct tcphdr *th, struct tcpcb *tp,
IN6_IS_ADDR_MULTICAST(&ip6->ip6_src))
goto drop;
/* IPv6 anycast check is done at tcp6_input() */
- } else
+ }
#endif
+#if defined(INET) && defined(INET6)
+ else
+#endif
+#ifdef INET
{
ip = mtod(m, struct ip *);
if (IN_MULTICAST(ntohl(ip->ip_dst.s_addr)) ||
@@ -3049,6 +3091,7 @@ tcp_dropwithreset(struct mbuf *m, struct tcphdr *th, struct tcpcb *tp,
in_broadcast(ip->ip_dst, m->m_pkthdr.rcvif))
goto drop;
}
+#endif
/* Perform bandwidth limiting. */
if (badport_bandlim(rstreason) < 0)
@@ -3308,8 +3351,8 @@ void
tcp_mss_update(struct tcpcb *tp, int offer,
struct hc_metrics_lite *metricptr, int *mtuflags)
{
- int mss;
- u_long maxmtu;
+ int mss = 0;
+ u_long maxmtu = 0;
struct inpcb *inp = tp->t_inpcb;
struct hc_metrics_lite metrics;
int origoffer = offer;
@@ -3329,12 +3372,17 @@ tcp_mss_update(struct tcpcb *tp, int offer,
if (isipv6) {
maxmtu = tcp_maxmtu6(&inp->inp_inc, mtuflags);
tp->t_maxopd = tp->t_maxseg = V_tcp_v6mssdflt;
- } else
+ }
#endif
+#if defined(INET) && defined(INET6)
+ else
+#endif
+#ifdef INET
{
maxmtu = tcp_maxmtu(&inp->inp_inc, mtuflags);
tp->t_maxopd = tp->t_maxseg = V_tcp_mssdflt;
}
+#endif
/*
* No route to sender, stay with default mss and return.
@@ -3395,14 +3443,19 @@ tcp_mss_update(struct tcpcb *tp, int offer,
if (!V_path_mtu_discovery &&
!in6_localaddr(&inp->in6p_faddr))
mss = min(mss, V_tcp_v6mssdflt);
- } else
+ }
#endif
+#if defined(INET) && defined(INET6)
+ else
+#endif
+#ifdef INET
{
mss = maxmtu - min_protoh;
if (!V_path_mtu_discovery &&
!in_localaddr(inp->inp_faddr))
mss = min(mss, V_tcp_mssdflt);
}
+#endif
/*
* XXX - The above conditional (mss = maxmtu - min_protoh)
* probably violates the TCP spec.
@@ -3540,14 +3593,19 @@ tcp_mssopt(struct in_conninfo *inc)
maxmtu = tcp_maxmtu6(inc, NULL);
thcmtu = tcp_hc_getmtu(inc); /* IPv4 and IPv6 */
min_protoh = sizeof(struct ip6_hdr) + sizeof(struct tcphdr);
- } else
+ }
+#endif
+#if defined(INET) && defined(INET6)
+ else
#endif
+#ifdef INET
{
mss = V_tcp_mssdflt;
maxmtu = tcp_maxmtu(inc, NULL);
thcmtu = tcp_hc_getmtu(inc); /* IPv4 and IPv6 */
min_protoh = sizeof(struct tcpiphdr);
}
+#endif
if (maxmtu && thcmtu)
mss = min(maxmtu, thcmtu) - min_protoh;
else if (maxmtu || thcmtu)
diff --git a/sys/netinet/tcp_output.c b/sys/netinet/tcp_output.c
index f6488a36090f..3ccb61a22332 100644
--- a/sys/netinet/tcp_output.c
+++ b/sys/netinet/tcp_output.c
@@ -173,7 +173,7 @@ tcp_output(struct tcpcb *tp)
{
struct socket *so = tp->t_inpcb->inp_socket;
long len, recwin, sendwin;
- int off, flags, error;
+ int off, flags, error = 0; /* Keep compiler happy */
struct mbuf *m;
struct ip *ip = NULL;
struct ipovly *ipov = NULL;
@@ -659,7 +659,7 @@ send:
hdrlen = sizeof (struct ip6_hdr) + sizeof (struct tcphdr);
else
#endif
- hdrlen = sizeof (struct tcpiphdr);
+ hdrlen = sizeof (struct tcpiphdr);
/*
* Compute options for segment.
@@ -866,7 +866,7 @@ send:
goto out;
}
}
-#endif
+#endif /* notyet */
/*
* If we're sending everything we've got, set PUSH.
* (This will keep happy those implementations which only
@@ -1189,7 +1189,7 @@ timer:
#endif
ipov->ih_len = save;
}
-#endif
+#endif /* TCPDEBUG */
/*
* Fill in IP length and desired time to live and
@@ -1216,8 +1216,12 @@ timer:
tp->t_inpcb->in6p_outputopts, NULL,
((so->so_options & SO_DONTROUTE) ?
IP_ROUTETOIF : 0), NULL, NULL, tp->t_inpcb);
- } else
+ }
#endif /* INET6 */
+#if defined(INET) && defined(INET6)
+ else
+#endif
+#ifdef INET
{
ip->ip_len = m->m_pkthdr.len;
#ifdef INET6
@@ -1239,6 +1243,7 @@ timer:
((so->so_options & SO_DONTROUTE) ? IP_ROUTETOIF : 0), 0,
tp->t_inpcb);
}
+#endif /* INET */
if (error) {
/*
diff --git a/sys/netinet/tcp_subr.c b/sys/netinet/tcp_subr.c
index f106b2d2e2b5..eafcb3dc315a 100644
--- a/sys/netinet/tcp_subr.c
+++ b/sys/netinet/tcp_subr.c
@@ -66,23 +66,20 @@ __FBSDID("$FreeBSD$");
#include <netinet/cc.h>
#include <netinet/in.h>
+#include <netinet/in_pcb.h>
#include <netinet/in_systm.h>
+#include <netinet/in_var.h>
#include <netinet/ip.h>
+#include <netinet/ip_icmp.h>
+#include <netinet/ip_var.h>
#ifdef INET6
#include <netinet/ip6.h>
-#endif
-#include <netinet/in_pcb.h>
-#ifdef INET6
#include <netinet6/in6_pcb.h>
-#endif
-#include <netinet/in_var.h>
-#include <netinet/ip_var.h>
-#ifdef INET6
#include <netinet6/ip6_var.h>
#include <netinet6/scope6_var.h>
#include <netinet6/nd6.h>
#endif
-#include <netinet/ip_icmp.h>
+
#include <netinet/tcp_fsm.h>
#include <netinet/tcp_seq.h>
#include <netinet/tcp_timer.h>
@@ -96,7 +93,9 @@ __FBSDID("$FreeBSD$");
#ifdef TCPDEBUG
#include <netinet/tcp_debug.h>
#endif
+#ifdef INET6
#include <netinet6/ip6protosw.h>
+#endif
#ifdef IPSEC
#include <netipsec/ipsec.h>
@@ -160,7 +159,7 @@ SYSCTL_VNET_PROC(_net_inet_tcp, TCPCTL_V6MSSDFLT, v6mssdflt,
CTLTYPE_INT|CTLFLAG_RW, &VNET_NAME(tcp_v6mssdflt), 0,
&sysctl_net_inet_tcp_mss_v6_check, "I",
"Default TCP Maximum Segment Size for IPv6");
-#endif
+#endif /* INET6 */
/*
* Minimum MSS we accept and use. This prevents DoS attacks where
@@ -414,8 +413,12 @@ tcpip_fillheaders(struct inpcb *inp, void *ip_ptr, void *tcp_ptr)
ip6->ip6_plen = htons(sizeof(struct tcphdr));
ip6->ip6_src = inp->in6p_laddr;
ip6->ip6_dst = inp->in6p_faddr;
- } else
+ }
+#endif /* INET6 */
+#if defined(INET6) && defined(INET)
+ else
#endif
+#ifdef INET
{
struct ip *ip;
@@ -432,6 +435,7 @@ tcpip_fillheaders(struct inpcb *inp, void *ip_ptr, void *tcp_ptr)
ip->ip_src = inp->inp_laddr;
ip->ip_dst = inp->inp_faddr;
}
+#endif /* INET */
th->th_sport = inp->inp_lport;
th->th_dport = inp->inp_fport;
th->th_seq = 0;
@@ -493,7 +497,7 @@ tcp_respond(struct tcpcb *tp, void *ipgen, struct tcphdr *th, struct mbuf *m,
KASSERT(tp != NULL || m != NULL, ("tcp_respond: tp and m both NULL"));
#ifdef INET6
- isipv6 = ((struct ip *)ipgen)->ip_v == 6;
+ isipv6 = ((struct ip *)ipgen)->ip_v == (IPV6_VERSION >> 4);
ip6 = ipgen;
#endif /* INET6 */
ip = ipgen;
@@ -574,8 +578,12 @@ tcp_respond(struct tcpcb *tp, void *ipgen, struct tcphdr *th, struct mbuf *m,
ip6->ip6_plen = htons((u_short)(sizeof (struct tcphdr) +
tlen));
tlen += sizeof (struct ip6_hdr) + sizeof (struct tcphdr);
- } else
+ }
#endif
+#if defined(INET) && defined(INET6)
+ else
+#endif
+#ifdef INET
{
tlen += sizeof (struct tcpiphdr);
ip->ip_len = tlen;
@@ -583,6 +591,7 @@ tcp_respond(struct tcpcb *tp, void *ipgen, struct tcphdr *th, struct mbuf *m,
if (V_path_mtu_discovery)
ip->ip_off |= IP_DF;
}
+#endif
m->m_len = tlen;
m->m_pkthdr.len = tlen;
m->m_pkthdr.rcvif = NULL;
@@ -620,14 +629,19 @@ tcp_respond(struct tcpcb *tp, void *ipgen, struct tcphdr *th, struct mbuf *m,
tlen - sizeof(struct ip6_hdr));
ip6->ip6_hlim = in6_selecthlim(tp != NULL ? tp->t_inpcb :
NULL, NULL);
- } else
+ }
#endif /* INET6 */
+#if defined(INET6) && defined(INET)
+ else
+#endif
+#ifdef INET
{
nth->th_sum = in_pseudo(ip->ip_src.s_addr, ip->ip_dst.s_addr,
htons((u_short)(tlen - sizeof(struct ip) + ip->ip_p)));
m->m_pkthdr.csum_flags = CSUM_TCP;
m->m_pkthdr.csum_data = offsetof(struct tcphdr, th_sum);
}
+#endif /* INET */
#ifdef TCPDEBUG
if (tp == NULL || (inp->inp_socket->so_options & SO_DEBUG))
tcp_trace(TA_OUTPUT, 0, tp, mtod(m, void *), th, 0);
@@ -635,9 +649,13 @@ tcp_respond(struct tcpcb *tp, void *ipgen, struct tcphdr *th, struct mbuf *m,
#ifdef INET6
if (isipv6)
(void) ip6_output(m, NULL, NULL, ipflags, NULL, NULL, inp);
- else
#endif /* INET6 */
- (void) ip_output(m, NULL, NULL, ipflags, NULL, inp);
+#if defined(INET) && defined(INET6)
+ else
+#endif
+#ifdef INET
+ (void) ip_output(m, NULL, NULL, ipflags, NULL, inp);
+#endif
}
/*
@@ -1200,6 +1218,7 @@ SYSCTL_PROC(_net_inet_tcp, TCPCTL_PCBLIST, pcblist,
CTLTYPE_OPAQUE | CTLFLAG_RD, NULL, 0,
tcp_pcblist, "S,xtcpcb", "List of active TCP connections");
+#ifdef INET
static int
tcp_getcred(SYSCTL_HANDLER_ARGS)
{
@@ -1239,6 +1258,7 @@ tcp_getcred(SYSCTL_HANDLER_ARGS)
SYSCTL_PROC(_net_inet_tcp, OID_AUTO, getcred,
CTLTYPE_OPAQUE|CTLFLAG_RW|CTLFLAG_PRISON, 0, 0,
tcp_getcred, "S,xucred", "Get the xucred of a TCP connection");
+#endif /* INET */
#ifdef INET6
static int
@@ -1247,7 +1267,10 @@ tcp6_getcred(SYSCTL_HANDLER_ARGS)
struct xucred xuc;
struct sockaddr_in6 addrs[2];
struct inpcb *inp;
- int error, mapped = 0;
+ int error;
+#ifdef INET
+ int mapped = 0;
+#endif
error = priv_check(req->td, PRIV_NETINET_GETCRED);
if (error)
@@ -1260,13 +1283,16 @@ tcp6_getcred(SYSCTL_HANDLER_ARGS)
return (error);
}
if (IN6_IS_ADDR_V4MAPPED(&addrs[0].sin6_addr)) {
+#ifdef INET
if (IN6_IS_ADDR_V4MAPPED(&addrs[1].sin6_addr))
mapped = 1;
else
+#endif
return (EINVAL);
}
INP_INFO_RLOCK(&V_tcbinfo);
+#ifdef INET
if (mapped == 1)
inp = in_pcblookup_hash(&V_tcbinfo,
*(struct in_addr *)&addrs[1].sin6_addr.s6_addr[12],
@@ -1275,6 +1301,7 @@ tcp6_getcred(SYSCTL_HANDLER_ARGS)
addrs[0].sin6_port,
0, NULL);
else
+#endif
inp = in6_pcblookup_hash(&V_tcbinfo,
&addrs[1].sin6_addr, addrs[1].sin6_port,
&addrs[0].sin6_addr, addrs[0].sin6_port, 0, NULL);
@@ -1300,9 +1327,10 @@ tcp6_getcred(SYSCTL_HANDLER_ARGS)
SYSCTL_PROC(_net_inet6_tcp6, OID_AUTO, getcred,
CTLTYPE_OPAQUE|CTLFLAG_RW|CTLFLAG_PRISON, 0, 0,
tcp6_getcred, "S,xucred", "Get the xucred of a TCP6 connection");
-#endif
+#endif /* INET6 */
+#ifdef INET
void
tcp_ctlinput(int cmd, struct sockaddr *sa, void *vip)
{
@@ -1415,6 +1443,7 @@ tcp_ctlinput(int cmd, struct sockaddr *sa, void *vip)
} else
in_pcbnotifyall(&V_tcbinfo, faddr, inetctlerrmap[cmd], notify);
}
+#endif /* INET */
#ifdef INET6
void
@@ -1694,6 +1723,7 @@ tcp_mtudisc(struct inpcb *inp, int errno)
return (inp);
}
+#ifdef INET
/*
* Look-up the routing entry to the peer of this inpcb. If no route
* is found and it cannot be allocated, then return 0. This routine
@@ -1735,6 +1765,7 @@ tcp_maxmtu(struct in_conninfo *inc, int *flags)
}
return (maxmtu);
}
+#endif /* INET */
#ifdef INET6
u_long
@@ -1858,11 +1889,15 @@ tcp_signature_compute(struct mbuf *m, int _unused, int len, int optlen,
u_char *buf, u_int direction)
{
union sockaddr_union dst;
+#ifdef INET
struct ippseudo ippseudo;
+#endif
MD5_CTX ctx;
int doff;
struct ip *ip;
+#ifdef INET
struct ipovly *ipovly;
+#endif
struct secasvar *sav;
struct tcphdr *th;
#ifdef INET6
@@ -1884,12 +1919,14 @@ tcp_signature_compute(struct mbuf *m, int _unused, int len, int optlen,
ip6 = NULL; /* Make the compiler happy. */
#endif
switch (ip->ip_v) {
+#ifdef INET
case IPVERSION:
dst.sa.sa_len = sizeof(struct sockaddr_in);
dst.sa.sa_family = AF_INET;
dst.sin.sin_addr = (direction == IPSEC_DIR_INBOUND) ?
ip->ip_src : ip->ip_dst;
break;
+#endif
#ifdef INET6
case (IPV6_VERSION >> 4):
ip6 = mtod(m, struct ip6_hdr *);
@@ -1929,6 +1966,7 @@ tcp_signature_compute(struct mbuf *m, int _unused, int len, int optlen,
* tcp_output(), the underlying ip_len member has not yet been set.
*/
switch (ip->ip_v) {
+#ifdef INET
case IPVERSION:
ipovly = (struct ipovly *)ip;
ippseudo.ippseudo_src = ipovly->ih_src;
@@ -1942,6 +1980,7 @@ tcp_signature_compute(struct mbuf *m, int _unused, int len, int optlen,
th = (struct tcphdr *)((u_char *)ip + sizeof(struct ip));
doff = sizeof(struct ip) + sizeof(struct tcphdr) + optlen;
break;
+#endif
#ifdef INET6
/*
* RFC 2385, 2.0 Proposal
@@ -2122,6 +2161,7 @@ sysctl_drop(SYSCTL_HANDLER_ARGS)
return (error);
break;
#endif
+#ifdef INET
case AF_INET:
fin = (struct sockaddr_in *)&addrs[0];
lin = (struct sockaddr_in *)&addrs[1];
@@ -2129,6 +2169,7 @@ sysctl_drop(SYSCTL_HANDLER_ARGS)
lin->sin_len != sizeof(struct sockaddr_in))
return (EINVAL);
break;
+#endif
default:
return (EINVAL);
}
@@ -2141,10 +2182,12 @@ sysctl_drop(SYSCTL_HANDLER_ARGS)
NULL);
break;
#endif
+#ifdef INET
case AF_INET:
inp = in_pcblookup_hash(&V_tcbinfo, fin->sin_addr,
fin->sin_port, lin->sin_addr, lin->sin_port, 0, NULL);
break;
+#endif
}
if (inp != NULL) {
INP_WLOCK(inp);
@@ -2272,6 +2315,7 @@ tcp_log_addr(struct in_conninfo *inc, struct tcphdr *th, void *ip4hdr,
sp = s + strlen(s);
sprintf(sp, "]:%i", ntohs(th->th_dport));
#endif /* INET6 */
+#ifdef INET
} else if (ip && th) {
inet_ntoa_r(ip->ip_src, sp);
sp = s + strlen(s);
@@ -2280,6 +2324,7 @@ tcp_log_addr(struct in_conninfo *inc, struct tcphdr *th, void *ip4hdr,
inet_ntoa_r(ip->ip_dst, sp);
sp = s + strlen(s);
sprintf(sp, "]:%i", ntohs(th->th_dport));
+#endif /* INET */
} else {
free(s, M_TCPLOG);
return (NULL);
diff --git a/sys/netinet/tcp_syncache.c b/sys/netinet/tcp_syncache.c
index be828ef006b8..8262f43aa32e 100644
--- a/sys/netinet/tcp_syncache.c
+++ b/sys/netinet/tcp_syncache.c
@@ -742,8 +742,12 @@ syncache_socket(struct syncache *sc, struct socket *lso, struct mbuf *m)
/* Override flowlabel from in6_pcbconnect. */
inp->inp_flow &= ~IPV6_FLOWLABEL_MASK;
inp->inp_flow |= sc->sc_flowlabel;
- } else
+ }
+#endif /* INET6 */
+#if defined(INET) && defined(INET6)
+ else
#endif
+#ifdef INET
{
struct in_addr laddr;
struct sockaddr_in sin;
@@ -775,6 +779,7 @@ syncache_socket(struct syncache *sc, struct socket *lso, struct mbuf *m)
goto abort;
}
}
+#endif /* INET */
tp = intotcpcb(inp);
tp->t_state = TCPS_SYN_RECEIVED;
tp->iss = sc->sc_iss;
@@ -1067,7 +1072,11 @@ _syncache_add(struct in_conninfo *inc, struct tcpopt *to, struct tcphdr *th,
#ifdef INET6
if (!(inc->inc_flags & INC_ISIPV6))
#endif
+#ifdef INET
ipopts = (m) ? ip_srcroute(m) : NULL;
+#else
+ ipopts = NULL;
+#endif
/*
* See if we already have an entry for this connection.
@@ -1301,8 +1310,8 @@ syncache_respond(struct syncache *sc)
{
struct ip *ip = NULL;
struct mbuf *m;
- struct tcphdr *th;
- int optlen, error;
+ struct tcphdr *th = NULL;
+ int optlen, error = 0; /* Make compiler happy */
u_int16_t hlen, tlen, mssopt;
struct tcpopt to;
#ifdef INET6
@@ -1350,8 +1359,12 @@ syncache_respond(struct syncache *sc)
ip6->ip6_flow |= sc->sc_flowlabel;
th = (struct tcphdr *)(ip6 + 1);
- } else
+ }
#endif
+#if defined(INET6) && defined(INET)
+ else
+#endif
+#ifdef INET
{
ip = mtod(m, struct ip *);
ip->ip_v = IPVERSION;
@@ -1378,6 +1391,7 @@ syncache_respond(struct syncache *sc)
th = (struct tcphdr *)(ip + 1);
}
+#endif /* INET */
th->th_sport = sc->sc_inc.inc_lport;
th->th_dport = sc->sc_inc.inc_fport;
@@ -1445,8 +1459,12 @@ syncache_respond(struct syncache *sc)
tlen + optlen - hlen);
ip6->ip6_hlim = in6_selecthlim(NULL, NULL);
error = ip6_output(m, NULL, NULL, 0, NULL, NULL, NULL);
- } else
+ }
#endif
+#if defined(INET6) && defined(INET)
+ else
+#endif
+#ifdef INET
{
th->th_sum = in_pseudo(ip->ip_src.s_addr, ip->ip_dst.s_addr,
htons(tlen + optlen - hlen + IPPROTO_TCP));
@@ -1454,6 +1472,7 @@ syncache_respond(struct syncache *sc)
m->m_pkthdr.csum_data = offsetof(struct tcphdr, th_sum);
error = ip_output(m, sc->sc_ipopts, NULL, 0, NULL, NULL);
}
+#endif
return (error);
}
diff --git a/sys/netinet/tcp_timewait.c b/sys/netinet/tcp_timewait.c
index aab950dab408..d283eb166da8 100644
--- a/sys/netinet/tcp_timewait.c
+++ b/sys/netinet/tcp_timewait.c
@@ -57,23 +57,19 @@ __FBSDID("$FreeBSD$");
#include <net/vnet.h>
#include <netinet/in.h>
+#include <netinet/in_pcb.h>
#include <netinet/in_systm.h>
+#include <netinet/in_var.h>
#include <netinet/ip.h>
+#include <netinet/ip_icmp.h>
+#include <netinet/ip_var.h>
#ifdef INET6
#include <netinet/ip6.h>
-#endif
-#include <netinet/in_pcb.h>
-#ifdef INET6
#include <netinet6/in6_pcb.h>
-#endif
-#include <netinet/in_var.h>
-#include <netinet/ip_var.h>
-#ifdef INET6
#include <netinet6/ip6_var.h>
#include <netinet6/scope6_var.h>
#include <netinet6/nd6.h>
#endif
-#include <netinet/ip_icmp.h>
#include <netinet/tcp.h>
#include <netinet/tcp_fsm.h>
#include <netinet/tcp_seq.h>
@@ -86,7 +82,9 @@ __FBSDID("$FreeBSD$");
#ifdef TCPDEBUG
#include <netinet/tcp_debug.h>
#endif
+#ifdef INET6
#include <netinet6/ip6protosw.h>
+#endif
#include <machine/in_cksum.h>
@@ -202,15 +200,31 @@ tcp_twstart(struct tcpcb *tp)
struct inpcb *inp = tp->t_inpcb;
int acknow;
struct socket *so;
+#ifdef INET6
+ int isipv6 = inp->inp_inc.inc_flags & INC_ISIPV6;
+#endif
INP_INFO_WLOCK_ASSERT(&V_tcbinfo); /* tcp_tw_2msl_reset(). */
INP_WLOCK_ASSERT(inp);
- if (V_nolocaltimewait && in_localip(inp->inp_faddr)) {
- tp = tcp_close(tp);
- if (tp != NULL)
- INP_WUNLOCK(inp);
- return;
+ if (V_nolocaltimewait) {
+ int error = 0;
+#ifdef INET6
+ if (isipv6)
+ error = in6_localaddr(&inp->in6p_faddr);
+#endif
+#if defined(INET6) && defined(INET)
+ else
+#endif
+#ifdef INET
+ error = in_localip(inp->inp_faddr);
+#endif
+ if (error) {
+ tp = tcp_close(tp);
+ if (tp != NULL)
+ INP_WUNLOCK(inp);
+ return;
+ }
}
tw = uma_zalloc(V_tcptw_zone, M_NOWAIT);
@@ -488,11 +502,15 @@ int
tcp_twrespond(struct tcptw *tw, int flags)
{
struct inpcb *inp = tw->tw_inpcb;
- struct tcphdr *th;
+#if defined(INET6) || defined(INET)
+ struct tcphdr *th = NULL;
+#endif
struct mbuf *m;
+#ifdef INET
struct ip *ip = NULL;
+#endif
u_int hdrlen, optlen;
- int error;
+ int error = 0; /* Keep compiler happy */
struct tcpopt to;
#ifdef INET6
struct ip6_hdr *ip6 = NULL;
@@ -516,14 +534,19 @@ tcp_twrespond(struct tcptw *tw, int flags)
ip6 = mtod(m, struct ip6_hdr *);
th = (struct tcphdr *)(ip6 + 1);
tcpip_fillheaders(inp, ip6, th);
- } else
+ }
#endif
+#if defined(INET6) && defined(INET)
+ else
+#endif
+#ifdef INET
{
hdrlen = sizeof(struct tcpiphdr);
ip = mtod(m, struct ip *);
th = (struct tcphdr *)(ip + 1);
tcpip_fillheaders(inp, ip, th);
}
+#endif
to.to_flags = 0;
/*
@@ -555,8 +578,12 @@ tcp_twrespond(struct tcptw *tw, int flags)
ip6->ip6_hlim = in6_selecthlim(inp, NULL);
error = ip6_output(m, inp->in6p_outputopts, NULL,
(tw->tw_so_options & SO_DONTROUTE), NULL, NULL, inp);
- } else
+ }
#endif
+#if defined(INET6) && defined(INET)
+ else
+#endif
+#ifdef INET
{
th->th_sum = in_pseudo(ip->ip_src.s_addr, ip->ip_dst.s_addr,
htons(sizeof(struct tcphdr) + optlen + IPPROTO_TCP));
@@ -569,6 +596,7 @@ tcp_twrespond(struct tcptw *tw, int flags)
((tw->tw_so_options & SO_DONTROUTE) ? IP_ROUTETOIF : 0),
NULL, inp);
}
+#endif
if (flags & TH_ACK)
TCPSTAT_INC(tcps_sndacks);
else
diff --git a/sys/netinet/tcp_usrreq.c b/sys/netinet/tcp_usrreq.c
index 6acf9dad83cd..318fe274a39d 100644
--- a/sys/netinet/tcp_usrreq.c
+++ b/sys/netinet/tcp_usrreq.c
@@ -64,17 +64,13 @@ __FBSDID("$FreeBSD$");
#include <netinet/cc.h>
#include <netinet/in.h>
-#include <netinet/in_systm.h>
-#ifdef INET6
-#include <netinet/ip6.h>
-#endif
#include <netinet/in_pcb.h>
-#ifdef INET6
-#include <netinet6/in6_pcb.h>
-#endif
+#include <netinet/in_systm.h>
#include <netinet/in_var.h>
#include <netinet/ip_var.h>
#ifdef INET6
+#include <netinet/ip6.h>
+#include <netinet6/in6_pcb.h>
#include <netinet6/ip6_var.h>
#include <netinet6/scope6_var.h>
#endif
@@ -92,8 +88,10 @@ __FBSDID("$FreeBSD$");
* TCP protocol interface to socket abstraction.
*/
static int tcp_attach(struct socket *);
+#ifdef INET
static int tcp_connect(struct tcpcb *, struct sockaddr *,
struct thread *td);
+#endif /* INET */
#ifdef INET6
static int tcp6_connect(struct tcpcb *, struct sockaddr *,
struct thread *td);
@@ -229,6 +227,7 @@ tcp_usr_detach(struct socket *so)
INP_INFO_WUNLOCK(&V_tcbinfo);
}
+#ifdef INET
/*
* Give the socket an address.
*/
@@ -270,6 +269,7 @@ out:
return (error);
}
+#endif /* INET */
#ifdef INET6
static int
@@ -304,6 +304,7 @@ tcp6_usr_bind(struct socket *so, struct sockaddr *nam, struct thread *td)
TCPDEBUG1();
inp->inp_vflag &= ~INP_IPV4;
inp->inp_vflag |= INP_IPV6;
+#ifdef INET
if ((inp->inp_flags & IN6P_IPV6_V6ONLY) == 0) {
if (IN6_IS_ADDR_UNSPECIFIED(&sin6p->sin6_addr))
inp->inp_vflag |= INP_IPV4;
@@ -318,6 +319,7 @@ tcp6_usr_bind(struct socket *so, struct sockaddr *nam, struct thread *td)
goto out;
}
}
+#endif
error = in6_pcbbind(inp, nam, td->td_ucred);
out:
TCPDEBUG2(PRU_BIND);
@@ -327,6 +329,7 @@ out:
}
#endif /* INET6 */
+#ifdef INET
/*
* Prepare to accept connections.
*/
@@ -365,6 +368,7 @@ out:
INP_INFO_WUNLOCK(&V_tcbinfo);
return (error);
}
+#endif /* INET */
#ifdef INET6
static int
@@ -407,6 +411,7 @@ out:
}
#endif /* INET6 */
+#ifdef INET
/*
* Initiate connection to peer.
* Create a template for use in transmissions on this connection.
@@ -454,6 +459,7 @@ out:
INP_INFO_WUNLOCK(&V_tcbinfo);
return (error);
}
+#endif /* INET */
#ifdef INET6
static int
@@ -486,6 +492,7 @@ tcp6_usr_connect(struct socket *so, struct sockaddr *nam, struct thread *td)
}
tp = intotcpcb(inp);
TCPDEBUG1();
+#ifdef INET
if (IN6_IS_ADDR_V4MAPPED(&sin6p->sin6_addr)) {
struct sockaddr_in sin;
@@ -505,6 +512,7 @@ tcp6_usr_connect(struct socket *so, struct sockaddr *nam, struct thread *td)
error = tcp_output_connect(so, nam);
goto out;
}
+#endif
inp->inp_vflag &= ~INP_IPV4;
inp->inp_vflag |= INP_IPV6;
inp->inp_inc.inc_flags |= INC_ISIPV6;
@@ -559,6 +567,7 @@ out:
return (error);
}
+#ifdef INET
/*
* Accept a connection. Essentially all the work is done at higher levels;
* just return the address of the peer, storing through addr.
@@ -610,6 +619,7 @@ out:
*nam = in_sockaddr(port, &addr);
return error;
}
+#endif /* INET */
#ifdef INET6
static int
@@ -799,9 +809,13 @@ tcp_usr_send(struct socket *so, int flags, struct mbuf *m,
#ifdef INET6
if (isipv6)
error = tcp6_connect(tp, nam, td);
- else
#endif /* INET6 */
- error = tcp_connect(tp, nam, td);
+#if defined(INET6) && defined(INET)
+ else
+#endif
+#ifdef INET
+ error = tcp_connect(tp, nam, td);
+#endif
if (error)
goto out;
tp->snd_wnd = TTCP_CLIENT_SND_WND;
@@ -859,9 +873,13 @@ tcp_usr_send(struct socket *so, int flags, struct mbuf *m,
#ifdef INET6
if (isipv6)
error = tcp6_connect(tp, nam, td);
- else
#endif /* INET6 */
- error = tcp_connect(tp, nam, td);
+#if defined(INET6) && defined(INET)
+ else
+#endif
+#ifdef INET
+ error = tcp_connect(tp, nam, td);
+#endif
if (error)
goto out;
tp->snd_wnd = TTCP_CLIENT_SND_WND;
@@ -1005,6 +1023,7 @@ out:
return (error);
}
+#ifdef INET
struct pr_usrreqs tcp_usrreqs = {
.pru_abort = tcp_usr_abort,
.pru_accept = tcp_usr_accept,
@@ -1024,6 +1043,7 @@ struct pr_usrreqs tcp_usrreqs = {
.pru_sosetlabel = in_pcbsosetlabel,
.pru_close = tcp_usr_close,
};
+#endif /* INET */
#ifdef INET6
struct pr_usrreqs tcp6_usrreqs = {
@@ -1047,6 +1067,7 @@ struct pr_usrreqs tcp6_usrreqs = {
};
#endif /* INET6 */
+#ifdef INET
/*
* Common subroutine to open a TCP connection to remote host specified
* by struct sockaddr_in in mbuf *nam. Call in_pcbbind to assign a local
@@ -1109,6 +1130,7 @@ tcp_connect(struct tcpcb *tp, struct sockaddr *nam, struct thread *td)
return 0;
}
+#endif /* INET */
#ifdef INET6
static int
@@ -1257,11 +1279,15 @@ tcp_ctloutput(struct socket *so, struct sockopt *sopt)
if (inp->inp_vflag & INP_IPV6PROTO) {
INP_WUNLOCK(inp);
error = ip6_ctloutput(so, sopt);
- } else {
+ }
#endif /* INET6 */
+#if defined(INET6) && defined(INET)
+ else
+#endif
+#ifdef INET
+ {
INP_WUNLOCK(inp);
error = ip_ctloutput(so, sopt);
-#ifdef INET6
}
#endif
return (error);