diff options
author | Ivan Delalande <colona@arista.com> | 2017-06-15 21:07:07 -0400 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2017-06-19 13:51:34 -0400 |
commit | 8917a777be3ba566377be05117f71b93a5fd909d (patch) | |
tree | 5ac57647291329d724de78027aab6125d7c13700 /net/ipv6/tcp_ipv6.c | |
parent | 6797318e623da68dfbacd0cb5c246f5ecd2baf6e (diff) |
tcp: md5: add TCP_MD5SIG_EXT socket option to set a key address prefix
Replace first padding in the tcp_md5sig structure with a new flag field
and address prefix length so it can be specified when configuring a new
key for TCP MD5 signature. The tcpm_flags field will only be used if the
socket option is TCP_MD5SIG_EXT to avoid breaking existing programs, and
tcpm_prefixlen only when the TCP_MD5SIG_FLAG_PREFIX flag is set.
Signed-off-by: Bob Gilligan <gilligan@arista.com>
Signed-off-by: Eric Mowat <mowat@arista.com>
Signed-off-by: Ivan Delalande <colona@arista.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'net/ipv6/tcp_ipv6.c')
-rw-r--r-- | net/ipv6/tcp_ipv6.c | 25 |
1 files changed, 18 insertions, 7 deletions
diff --git a/net/ipv6/tcp_ipv6.c b/net/ipv6/tcp_ipv6.c index 261689310408..68dc7472b44d 100644 --- a/net/ipv6/tcp_ipv6.c +++ b/net/ipv6/tcp_ipv6.c | |||
@@ -515,11 +515,12 @@ static struct tcp_md5sig_key *tcp_v6_md5_lookup(const struct sock *sk, | |||
515 | return tcp_v6_md5_do_lookup(sk, &addr_sk->sk_v6_daddr); | 515 | return tcp_v6_md5_do_lookup(sk, &addr_sk->sk_v6_daddr); |
516 | } | 516 | } |
517 | 517 | ||
518 | static int tcp_v6_parse_md5_keys(struct sock *sk, char __user *optval, | 518 | static int tcp_v6_parse_md5_keys(struct sock *sk, int optname, |
519 | int optlen) | 519 | char __user *optval, int optlen) |
520 | { | 520 | { |
521 | struct tcp_md5sig cmd; | 521 | struct tcp_md5sig cmd; |
522 | struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)&cmd.tcpm_addr; | 522 | struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)&cmd.tcpm_addr; |
523 | u8 prefixlen; | ||
523 | 524 | ||
524 | if (optlen < sizeof(cmd)) | 525 | if (optlen < sizeof(cmd)) |
525 | return -EINVAL; | 526 | return -EINVAL; |
@@ -530,12 +531,22 @@ static int tcp_v6_parse_md5_keys(struct sock *sk, char __user *optval, | |||
530 | if (sin6->sin6_family != AF_INET6) | 531 | if (sin6->sin6_family != AF_INET6) |
531 | return -EINVAL; | 532 | return -EINVAL; |
532 | 533 | ||
534 | if (optname == TCP_MD5SIG_EXT && | ||
535 | cmd.tcpm_flags & TCP_MD5SIG_FLAG_PREFIX) { | ||
536 | prefixlen = cmd.tcpm_prefixlen; | ||
537 | if (prefixlen > 128 || (ipv6_addr_v4mapped(&sin6->sin6_addr) && | ||
538 | prefixlen > 32)) | ||
539 | return -EINVAL; | ||
540 | } else { | ||
541 | prefixlen = ipv6_addr_v4mapped(&sin6->sin6_addr) ? 32 : 128; | ||
542 | } | ||
543 | |||
533 | if (!cmd.tcpm_keylen) { | 544 | if (!cmd.tcpm_keylen) { |
534 | if (ipv6_addr_v4mapped(&sin6->sin6_addr)) | 545 | if (ipv6_addr_v4mapped(&sin6->sin6_addr)) |
535 | return tcp_md5_do_del(sk, (union tcp_md5_addr *)&sin6->sin6_addr.s6_addr32[3], | 546 | return tcp_md5_do_del(sk, (union tcp_md5_addr *)&sin6->sin6_addr.s6_addr32[3], |
536 | AF_INET, 32); | 547 | AF_INET, prefixlen); |
537 | return tcp_md5_do_del(sk, (union tcp_md5_addr *)&sin6->sin6_addr, | 548 | return tcp_md5_do_del(sk, (union tcp_md5_addr *)&sin6->sin6_addr, |
538 | AF_INET6, 128); | 549 | AF_INET6, prefixlen); |
539 | } | 550 | } |
540 | 551 | ||
541 | if (cmd.tcpm_keylen > TCP_MD5SIG_MAXKEYLEN) | 552 | if (cmd.tcpm_keylen > TCP_MD5SIG_MAXKEYLEN) |
@@ -543,12 +554,12 @@ static int tcp_v6_parse_md5_keys(struct sock *sk, char __user *optval, | |||
543 | 554 | ||
544 | if (ipv6_addr_v4mapped(&sin6->sin6_addr)) | 555 | if (ipv6_addr_v4mapped(&sin6->sin6_addr)) |
545 | return tcp_md5_do_add(sk, (union tcp_md5_addr *)&sin6->sin6_addr.s6_addr32[3], | 556 | return tcp_md5_do_add(sk, (union tcp_md5_addr *)&sin6->sin6_addr.s6_addr32[3], |
546 | AF_INET, 32, cmd.tcpm_key, | 557 | AF_INET, prefixlen, cmd.tcpm_key, |
547 | cmd.tcpm_keylen, GFP_KERNEL); | 558 | cmd.tcpm_keylen, GFP_KERNEL); |
548 | 559 | ||
549 | return tcp_md5_do_add(sk, (union tcp_md5_addr *)&sin6->sin6_addr, | 560 | return tcp_md5_do_add(sk, (union tcp_md5_addr *)&sin6->sin6_addr, |
550 | AF_INET6, 128, cmd.tcpm_key, cmd.tcpm_keylen, | 561 | AF_INET6, prefixlen, cmd.tcpm_key, |
551 | GFP_KERNEL); | 562 | cmd.tcpm_keylen, GFP_KERNEL); |
552 | } | 563 | } |
553 | 564 | ||
554 | static int tcp_v6_md5_hash_headers(struct tcp_md5sig_pool *hp, | 565 | static int tcp_v6_md5_hash_headers(struct tcp_md5sig_pool *hp, |