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>
This commit is contained in:

committed by
David S. Miller

parent
6797318e62
commit
8917a777be
@@ -1066,11 +1066,12 @@ static void tcp_clear_md5_list(struct sock *sk)
|
||||
}
|
||||
}
|
||||
|
||||
static int tcp_v4_parse_md5_keys(struct sock *sk, char __user *optval,
|
||||
int optlen)
|
||||
static int tcp_v4_parse_md5_keys(struct sock *sk, int optname,
|
||||
char __user *optval, int optlen)
|
||||
{
|
||||
struct tcp_md5sig cmd;
|
||||
struct sockaddr_in *sin = (struct sockaddr_in *)&cmd.tcpm_addr;
|
||||
u8 prefixlen = 32;
|
||||
|
||||
if (optlen < sizeof(cmd))
|
||||
return -EINVAL;
|
||||
@@ -1081,15 +1082,22 @@ static int tcp_v4_parse_md5_keys(struct sock *sk, char __user *optval,
|
||||
if (sin->sin_family != AF_INET)
|
||||
return -EINVAL;
|
||||
|
||||
if (optname == TCP_MD5SIG_EXT &&
|
||||
cmd.tcpm_flags & TCP_MD5SIG_FLAG_PREFIX) {
|
||||
prefixlen = cmd.tcpm_prefixlen;
|
||||
if (prefixlen > 32)
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
if (!cmd.tcpm_keylen)
|
||||
return tcp_md5_do_del(sk, (union tcp_md5_addr *)&sin->sin_addr.s_addr,
|
||||
AF_INET, 32);
|
||||
AF_INET, prefixlen);
|
||||
|
||||
if (cmd.tcpm_keylen > TCP_MD5SIG_MAXKEYLEN)
|
||||
return -EINVAL;
|
||||
|
||||
return tcp_md5_do_add(sk, (union tcp_md5_addr *)&sin->sin_addr.s_addr,
|
||||
AF_INET, 32, cmd.tcpm_key, cmd.tcpm_keylen,
|
||||
AF_INET, prefixlen, cmd.tcpm_key, cmd.tcpm_keylen,
|
||||
GFP_KERNEL);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user