Skip to content

Commit cd2c0f4

Browse files
David Aherndavem330
authored andcommitted
net: Update raw socket bind to consider l3 domain
Binding a raw socket to a local address fails if the socket is bound to an L3 domain: $ vrf-test -s -l 10.100.1.2 -R -I red error binding socket: 99: Cannot assign requested address Update raw_bind to look consider if sk_bound_dev_if is bound to an L3 domain and use inet_addr_type_table to lookup the address. Signed-off-by: David Ahern <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 0ca6e00 commit cd2c0f4

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

net/ipv4/raw.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -695,12 +695,20 @@ static int raw_bind(struct sock *sk, struct sockaddr *uaddr, int addr_len)
695695
{
696696
struct inet_sock *inet = inet_sk(sk);
697697
struct sockaddr_in *addr = (struct sockaddr_in *) uaddr;
698+
u32 tb_id = RT_TABLE_LOCAL;
698699
int ret = -EINVAL;
699700
int chk_addr_ret;
700701

701702
if (sk->sk_state != TCP_CLOSE || addr_len < sizeof(struct sockaddr_in))
702703
goto out;
703-
chk_addr_ret = inet_addr_type(sock_net(sk), addr->sin_addr.s_addr);
704+
705+
if (sk->sk_bound_dev_if)
706+
tb_id = l3mdev_fib_table_by_index(sock_net(sk),
707+
sk->sk_bound_dev_if) ? : tb_id;
708+
709+
chk_addr_ret = inet_addr_type_table(sock_net(sk), addr->sin_addr.s_addr,
710+
tb_id);
711+
704712
ret = -EADDRNOTAVAIL;
705713
if (addr->sin_addr.s_addr && chk_addr_ret != RTN_LOCAL &&
706714
chk_addr_ret != RTN_MULTICAST && chk_addr_ret != RTN_BROADCAST)

0 commit comments

Comments
 (0)