diff options
author | bms <bms@FreeBSD.org> | 2004-02-11 04:26:04 +0000 |
---|---|---|
committer | bms <bms@FreeBSD.org> | 2004-02-11 04:26:04 +0000 |
commit | 903cdeea1a6d0c99fecc1d8aeeab65bdfbab46d7 (patch) | |
tree | 7a14054c69fb5681c86f54e9b66a9128c1e16003 /sys/netinet/tcp_output.c | |
parent | dfc906ec95fc478c611f5ef93b40dc04b3ecb6e8 (diff) | |
download | FreeBSD-src-903cdeea1a6d0c99fecc1d8aeeab65bdfbab46d7.zip FreeBSD-src-903cdeea1a6d0c99fecc1d8aeeab65bdfbab46d7.tar.gz |
Initial import of RFC 2385 (TCP-MD5) digest support.
This is the first of two commits; bringing in the kernel support first.
This can be enabled by compiling a kernel with options TCP_SIGNATURE
and FAST_IPSEC.
For the uninitiated, this is a TCP option which provides for a means of
authenticating TCP sessions which came into being before IPSEC. It is
still relevant today, however, as it is used by many commercial router
vendors, particularly with BGP, and as such has become a requirement for
interconnect at many major Internet points of presence.
Several parts of the TCP and IP headers, including the segment payload,
are digested with MD5, including a shared secret. The PF_KEY interface
is used to manage the secrets using security associations in the SADB.
There is a limitation here in that as there is no way to map a TCP flow
per-port back to an SPI without polluting tcpcb or using the SPD; the
code to do the latter is unstable at this time. Therefore this code only
supports per-host keying granularity.
Whilst FAST_IPSEC is mutually exclusive with KAME IPSEC (and thus IPv6),
TCP_SIGNATURE applies only to IPv4. For the vast majority of prospective
users of this feature, this will not pose any problem.
This implementation is output-only; that is, the option is honoured when
responding to a host initiating a TCP session, but no effort is made
[yet] to authenticate inbound traffic. This is, however, sufficient to
interwork with Cisco equipment.
Tested with a Cisco 2501 running IOS 12.0(27), and Quagga 0.96.4 with
local patches. Patches for tcpdump to validate TCP-MD5 sessions are also
available from me upon request.
Sponsored by: sentex.net
Diffstat (limited to 'sys/netinet/tcp_output.c')
-rw-r--r-- | sys/netinet/tcp_output.c | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/sys/netinet/tcp_output.c b/sys/netinet/tcp_output.c index f30d6c3..c868033 100644 --- a/sys/netinet/tcp_output.c +++ b/sys/netinet/tcp_output.c @@ -34,6 +34,7 @@ * $FreeBSD$ */ +#include "opt_inet.h" #include "opt_inet6.h" #include "opt_ipsec.h" #include "opt_mac.h" @@ -115,6 +116,7 @@ tcp_output(struct tcpcb *tp) struct socket *so = tp->t_inpcb->inp_socket; long len, recwin, sendwin; int off, flags, error; + int sigoff = 0; struct mbuf *m; struct ip *ip = NULL; struct ipovly *ipov = NULL; @@ -537,6 +539,32 @@ send: } } +#ifdef TCP_SIGNATURE +#ifdef INET6 + if (!isipv6) +#endif + if (tp->t_flags & TF_SIGNATURE) { + int i; + u_char *bp; + /* + * Initialize TCP-MD5 option (RFC2385) + */ + bp = (u_char *)opt + optlen; + *bp++ = TCPOPT_SIGNATURE; + *bp++ = TCPOLEN_SIGNATURE; + sigoff = optlen + 2; + for (i = 0; i < TCP_SIGLEN; i++) + *bp++ = 0; + optlen += TCPOLEN_SIGNATURE; + /* + * Terminate options list and maintain 32-bit alignment. + */ + *bp++ = TCPOPT_NOP; + *bp++ = TCPOPT_EOL; + optlen += 2; + } +#endif /* TCP_SIGNATURE */ + hdrlen += optlen; #ifdef INET6 @@ -754,6 +782,15 @@ send: */ tp->snd_up = tp->snd_una; /* drag it along */ +#ifdef TCP_SIGNATURE +#ifdef INET6 + if (!isipv6) +#endif + if (tp->t_flags & TF_SIGNATURE) + tcpsignature_compute(m, sizeof(struct ip), len, optlen, + (u_char *)(th + 1) + sigoff, IPSEC_DIR_OUTBOUND); +#endif /* TCP_SIGNATURE */ + /* * Put TCP length in extended header, and then * checksum extended header and data. |