From: Stephen Hemminger <shemminger@vyatta.com>
To: David Miller <davem@davemloft.net>
Cc: netdev@vger.kernel.org, linux-api@vger.kernel.org
Subject: [PATCH] tcp: Generalized TTL Security Mechanism
Date: Sun, 10 Jan 2010 22:00:34 -0800 [thread overview]
Message-ID: <20100110220034.4d46ba8a@nehalam> (raw)
This patch adds the kernel portions needed to implement
RFC 5082 Generalized TTL Security Mechanism (GTSM).
It is a lightweight security measure against forged
packets causing DoS attacks (for BGP).
This is already implemented the same way in BSD kernels.
For the necessary Quagga patch
http://www.gossamer-threads.com/lists/quagga/dev/17389
Description from Cisco
http://www.cisco.com/en/US/docs/ios/12_3t/12_3t7/feature/guide/gt_btsh.html
It does add one byte to each socket structure, but I did
a little rearrangement to reuse a hole (on 64 bit), but it
does grow the structure on 32 bit
This should be documented on ip(4) man page and the Glibc in.h
file also needs update. IPV6_MINHOPLIMIT should also be added
(although BSD doesn't support that).
Only TCP is supported, but could also be added to UDP, DCCP, SCTP
if desired.
Signed-off-by: Stephen Hemminger <shemminger@vyatta.com>
---
include/linux/in.h | 1 +
include/net/inet_sock.h | 9 +++++++++
net/ipv4/ip_sockglue.c | 14 +++++++++++++-
net/ipv4/tcp_ipv4.c | 2 ++
4 files changed, 25 insertions(+), 1 deletion(-)
--- a/include/linux/in.h 2010-01-10 21:06:42.873122656 -0800
+++ b/include/linux/in.h 2010-01-10 21:06:47.802185618 -0800
@@ -84,6 +84,8 @@ struct in_addr {
#define IP_ORIGDSTADDR 20
#define IP_RECVORIGDSTADDR IP_ORIGDSTADDR
+#define IP_MINTTL 21
+
/* IP_MTU_DISCOVER values */
#define IP_PMTUDISC_DONT 0 /* Never send DF frames */
#define IP_PMTUDISC_WANT 1 /* Use per route hints */
--- a/include/net/inet_sock.h 2010-01-10 21:06:42.893123288 -0800
+++ b/include/net/inet_sock.h 2010-01-10 21:17:50.262842588 -0800
@@ -122,10 +122,12 @@ struct inet_sock {
__be32 inet_saddr;
__s16 uc_ttl;
__u16 cmsg_flags;
- struct ip_options *opt;
__be16 inet_sport;
__u16 inet_id;
+
+ struct ip_options *opt;
__u8 tos;
+ __u8 min_ttl;
__u8 mc_ttl;
__u8 pmtudisc;
__u8 recverr:1,
--- a/net/ipv4/ip_sockglue.c 2010-01-10 21:06:42.913123212 -0800
+++ b/net/ipv4/ip_sockglue.c 2010-01-10 21:06:47.822184879 -0800
@@ -451,7 +451,8 @@ static int do_ip_setsockopt(struct sock
(1<<IP_TTL) | (1<<IP_HDRINCL) |
(1<<IP_MTU_DISCOVER) | (1<<IP_RECVERR) |
(1<<IP_ROUTER_ALERT) | (1<<IP_FREEBIND) |
- (1<<IP_PASSSEC) | (1<<IP_TRANSPARENT))) ||
+ (1<<IP_PASSSEC) | (1<<IP_TRANSPARENT) |
+ (1<<IP_MINTTL))) ||
optname == IP_MULTICAST_TTL ||
optname == IP_MULTICAST_ALL ||
optname == IP_MULTICAST_LOOP ||
@@ -936,6 +937,14 @@ mc_msf_out:
inet->transparent = !!val;
break;
+ case IP_MINTTL:
+ if (optlen < 1)
+ goto e_inval;
+ if (val < 0 || val > 255)
+ goto e_inval;
+ inet->min_ttl = val;
+ break;
+
default:
err = -ENOPROTOOPT;
break;
@@ -1198,6 +1207,9 @@ static int do_ip_getsockopt(struct sock
case IP_TRANSPARENT:
val = inet->transparent;
break;
+ case IP_MINTTL:
+ val = inet->min_ttl;
+ break;
default:
release_sock(sk);
return -ENOPROTOOPT;
--- a/net/ipv4/tcp_ipv4.c 2010-01-10 21:06:42.931093698 -0800
+++ b/net/ipv4/tcp_ipv4.c 2010-01-10 21:08:21.537513427 -0800
@@ -1649,6 +1649,9 @@ int tcp_v4_rcv(struct sk_buff *skb)
if (!sk)
goto no_tcp_socket;
+ if (iph->ttl < inet_sk(sk)->min_ttl)
+ goto discard_and_relse;
+
process:
if (sk->sk_state == TCP_TIME_WAIT)
goto do_time_wait;
next reply other threads:[~2010-01-11 6:00 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-01-11 6:00 Stephen Hemminger [this message]
2010-01-11 11:25 ` [PATCH] tcp: Generalized TTL Security Mechanism Eric Dumazet
[not found] ` <4B4B0AA3.6010207-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2010-01-11 16:25 ` Stephen Hemminger
2010-01-11 17:04 ` Eric Dumazet
2010-01-11 17:10 ` Eric Dumazet
[not found] ` <4B4B5B84.3090409-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2010-01-12 0:27 ` David Miller
2010-01-12 0:28 ` David Miller
2010-01-14 10:58 ` Andi Kleen
[not found] ` <873a29eywq.fsf-3rXA9MLqAseW/qJFnhkgxti2O/JbrIOy@public.gmane.org>
2010-01-14 11:04 ` David Miller
[not found] ` <20100114.030454.16178889.davem-fT/PcQaiUtIeIZ0/mPfg9Q@public.gmane.org>
2010-01-14 11:22 ` Andi Kleen
[not found] ` <20100114112216.GK12241-u0/ZJuX+froe6aEkudXLsA@public.gmane.org>
2010-01-14 11:27 ` David Miller
2010-01-14 12:38 ` William Allen Simpson
[not found] ` <4B4F1044.8080500-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2010-01-14 13:14 ` Eric Dumazet
2010-03-18 6:36 ` Pekka Savola
2010-03-18 17:59 ` Stephen Hemminger
2010-03-19 7:58 ` Pekka Savola
2010-03-19 8:21 ` Eric Dumazet
2010-03-19 8:28 ` Pekka Savola
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20100110220034.4d46ba8a@nehalam \
--to=shemminger@vyatta.com \
--cc=davem@davemloft.net \
--cc=linux-api@vger.kernel.org \
--cc=netdev@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.