diff options
-rw-r--r-- | include/linux/in.h | 1 | ||||
-rw-r--r-- | include/net/inet_sock.h | 2 | ||||
-rw-r--r-- | net/ipv4/ip_sockglue.c | 33 | ||||
-rw-r--r-- | net/ipv4/ping.c | 3 | ||||
-rw-r--r-- | net/ipv4/raw.c | 3 | ||||
-rw-r--r-- | net/ipv4/udp.c | 3 |
6 files changed, 42 insertions, 3 deletions
diff --git a/include/linux/in.h b/include/linux/in.h index 01129c0ea87c..e0337f11d92e 100644 --- a/include/linux/in.h +++ b/include/linux/in.h | |||
@@ -111,6 +111,7 @@ struct in_addr { | |||
111 | #define MCAST_LEAVE_SOURCE_GROUP 47 | 111 | #define MCAST_LEAVE_SOURCE_GROUP 47 |
112 | #define MCAST_MSFILTER 48 | 112 | #define MCAST_MSFILTER 48 |
113 | #define IP_MULTICAST_ALL 49 | 113 | #define IP_MULTICAST_ALL 49 |
114 | #define IP_UNICAST_IF 50 | ||
114 | 115 | ||
115 | #define MCAST_EXCLUDE 0 | 116 | #define MCAST_EXCLUDE 0 |
116 | #define MCAST_INCLUDE 1 | 117 | #define MCAST_INCLUDE 1 |
diff --git a/include/net/inet_sock.h b/include/net/inet_sock.h index e3e405106afe..022f772c0ebe 100644 --- a/include/net/inet_sock.h +++ b/include/net/inet_sock.h | |||
@@ -132,6 +132,7 @@ struct rtable; | |||
132 | * @tos - TOS | 132 | * @tos - TOS |
133 | * @mc_ttl - Multicasting TTL | 133 | * @mc_ttl - Multicasting TTL |
134 | * @is_icsk - is this an inet_connection_sock? | 134 | * @is_icsk - is this an inet_connection_sock? |
135 | * @uc_index - Unicast outgoing device index | ||
135 | * @mc_index - Multicast device index | 136 | * @mc_index - Multicast device index |
136 | * @mc_list - Group array | 137 | * @mc_list - Group array |
137 | * @cork - info to build ip hdr on each ip frag while socket is corked | 138 | * @cork - info to build ip hdr on each ip frag while socket is corked |
@@ -167,6 +168,7 @@ struct inet_sock { | |||
167 | transparent:1, | 168 | transparent:1, |
168 | mc_all:1, | 169 | mc_all:1, |
169 | nodefrag:1; | 170 | nodefrag:1; |
171 | int uc_index; | ||
170 | int mc_index; | 172 | int mc_index; |
171 | __be32 mc_addr; | 173 | __be32 mc_addr; |
172 | struct ip_mc_socklist __rcu *mc_list; | 174 | struct ip_mc_socklist __rcu *mc_list; |
diff --git a/net/ipv4/ip_sockglue.c b/net/ipv4/ip_sockglue.c index 8aa87c19fa00..9125529dab95 100644 --- a/net/ipv4/ip_sockglue.c +++ b/net/ipv4/ip_sockglue.c | |||
@@ -469,6 +469,7 @@ static int do_ip_setsockopt(struct sock *sk, int level, | |||
469 | (1<<IP_ROUTER_ALERT) | (1<<IP_FREEBIND) | | 469 | (1<<IP_ROUTER_ALERT) | (1<<IP_FREEBIND) | |
470 | (1<<IP_PASSSEC) | (1<<IP_TRANSPARENT) | | 470 | (1<<IP_PASSSEC) | (1<<IP_TRANSPARENT) | |
471 | (1<<IP_MINTTL) | (1<<IP_NODEFRAG))) || | 471 | (1<<IP_MINTTL) | (1<<IP_NODEFRAG))) || |
472 | optname == IP_UNICAST_IF || | ||
472 | optname == IP_MULTICAST_TTL || | 473 | optname == IP_MULTICAST_TTL || |
473 | optname == IP_MULTICAST_ALL || | 474 | optname == IP_MULTICAST_ALL || |
474 | optname == IP_MULTICAST_LOOP || | 475 | optname == IP_MULTICAST_LOOP || |
@@ -628,6 +629,35 @@ static int do_ip_setsockopt(struct sock *sk, int level, | |||
628 | goto e_inval; | 629 | goto e_inval; |
629 | inet->mc_loop = !!val; | 630 | inet->mc_loop = !!val; |
630 | break; | 631 | break; |
632 | case IP_UNICAST_IF: | ||
633 | { | ||
634 | struct net_device *dev = NULL; | ||
635 | int ifindex; | ||
636 | |||
637 | if (optlen != sizeof(int)) | ||
638 | goto e_inval; | ||
639 | |||
640 | ifindex = (__force int)ntohl((__force __be32)val); | ||
641 | if (ifindex == 0) { | ||
642 | inet->uc_index = 0; | ||
643 | err = 0; | ||
644 | break; | ||
645 | } | ||
646 | |||
647 | dev = dev_get_by_index(sock_net(sk), ifindex); | ||
648 | err = -EADDRNOTAVAIL; | ||
649 | if (!dev) | ||
650 | break; | ||
651 | dev_put(dev); | ||
652 | |||
653 | err = -EINVAL; | ||
654 | if (sk->sk_bound_dev_if) | ||
655 | break; | ||
656 | |||
657 | inet->uc_index = ifindex; | ||
658 | err = 0; | ||
659 | break; | ||
660 | } | ||
631 | case IP_MULTICAST_IF: | 661 | case IP_MULTICAST_IF: |
632 | { | 662 | { |
633 | struct ip_mreqn mreq; | 663 | struct ip_mreqn mreq; |
@@ -1178,6 +1208,9 @@ static int do_ip_getsockopt(struct sock *sk, int level, int optname, | |||
1178 | case IP_MULTICAST_LOOP: | 1208 | case IP_MULTICAST_LOOP: |
1179 | val = inet->mc_loop; | 1209 | val = inet->mc_loop; |
1180 | break; | 1210 | break; |
1211 | case IP_UNICAST_IF: | ||
1212 | val = (__force int)htonl((__u32) inet->uc_index); | ||
1213 | break; | ||
1181 | case IP_MULTICAST_IF: | 1214 | case IP_MULTICAST_IF: |
1182 | { | 1215 | { |
1183 | struct in_addr addr; | 1216 | struct in_addr addr; |
diff --git a/net/ipv4/ping.c b/net/ipv4/ping.c index aea5a199c37a..cfc82cf339f6 100644 --- a/net/ipv4/ping.c +++ b/net/ipv4/ping.c | |||
@@ -556,7 +556,8 @@ static int ping_sendmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg, | |||
556 | ipc.oif = inet->mc_index; | 556 | ipc.oif = inet->mc_index; |
557 | if (!saddr) | 557 | if (!saddr) |
558 | saddr = inet->mc_addr; | 558 | saddr = inet->mc_addr; |
559 | } | 559 | } else if (!ipc.oif) |
560 | ipc.oif = inet->uc_index; | ||
560 | 561 | ||
561 | flowi4_init_output(&fl4, ipc.oif, sk->sk_mark, tos, | 562 | flowi4_init_output(&fl4, ipc.oif, sk->sk_mark, tos, |
562 | RT_SCOPE_UNIVERSE, sk->sk_protocol, | 563 | RT_SCOPE_UNIVERSE, sk->sk_protocol, |
diff --git a/net/ipv4/raw.c b/net/ipv4/raw.c index 3ccda5ae8a27..ab466305b629 100644 --- a/net/ipv4/raw.c +++ b/net/ipv4/raw.c | |||
@@ -563,7 +563,8 @@ static int raw_sendmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg, | |||
563 | ipc.oif = inet->mc_index; | 563 | ipc.oif = inet->mc_index; |
564 | if (!saddr) | 564 | if (!saddr) |
565 | saddr = inet->mc_addr; | 565 | saddr = inet->mc_addr; |
566 | } | 566 | } else if (!ipc.oif) |
567 | ipc.oif = inet->uc_index; | ||
567 | 568 | ||
568 | flowi4_init_output(&fl4, ipc.oif, sk->sk_mark, tos, | 569 | flowi4_init_output(&fl4, ipc.oif, sk->sk_mark, tos, |
569 | RT_SCOPE_UNIVERSE, | 570 | RT_SCOPE_UNIVERSE, |
diff --git a/net/ipv4/udp.c b/net/ipv4/udp.c index 5d075b5f70fc..cd99f1a0f59f 100644 --- a/net/ipv4/udp.c +++ b/net/ipv4/udp.c | |||
@@ -917,7 +917,8 @@ int udp_sendmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg, | |||
917 | if (!saddr) | 917 | if (!saddr) |
918 | saddr = inet->mc_addr; | 918 | saddr = inet->mc_addr; |
919 | connected = 0; | 919 | connected = 0; |
920 | } | 920 | } else if (!ipc.oif) |
921 | ipc.oif = inet->uc_index; | ||
921 | 922 | ||
922 | if (connected) | 923 | if (connected) |
923 | rt = (struct rtable *)sk_dst_check(sk, 0); | 924 | rt = (struct rtable *)sk_dst_check(sk, 0); |