diff options
author | Erich E. Hoover <ehoover@mines.edu> | 2012-02-08 04:11:07 -0500 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2012-02-08 15:52:45 -0500 |
commit | 76e21053b5bf33a07c76f99d27a74238310e3c71 (patch) | |
tree | 70ac2a67be8f19da96896950447567e156975149 /net/ipv4/ip_sockglue.c | |
parent | 43480aecb1f538d4f6dd8b2c5d2b71fb98659072 (diff) |
ipv4: Implement IP_UNICAST_IF socket option.
The IP_UNICAST_IF feature is needed by the Wine project. This patch
implements the feature by setting the outgoing interface in a similar
fashion to that of IP_MULTICAST_IF. A separate option is needed to
handle this feature since the existing options do not provide all of
the characteristics required by IP_UNICAST_IF, a summary is provided
below.
SO_BINDTODEVICE:
* SO_BINDTODEVICE requires administrative privileges, IP_UNICAST_IF
does not. From reading some old mailing list articles my
understanding is that SO_BINDTODEVICE requires administrative
privileges because it can override the administrator's routing
settings.
* The SO_BINDTODEVICE option restricts both outbound and inbound
traffic, IP_UNICAST_IF only impacts outbound traffic.
IP_PKTINFO:
* Since IP_PKTINFO and IP_UNICAST_IF are independent options,
implementing IP_UNICAST_IF with IP_PKTINFO will likely break some
applications.
* Implementing IP_UNICAST_IF on top of IP_PKTINFO significantly
complicates the Wine codebase and reduces the socket performance
(doing this requires a lot of extra communication between the
"server" and "user" layers).
bind():
* bind() does not work on broadcast packets, IP_UNICAST_IF is
specifically intended to work with broadcast packets.
* Like SO_BINDTODEVICE, bind() restricts both outbound and inbound
traffic.
Signed-off-by: Erich E. Hoover <ehoover@mines.edu>
Signed-off-by: Eric Dumazet <eric.dumazet@gmail.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'net/ipv4/ip_sockglue.c')
-rw-r--r-- | net/ipv4/ip_sockglue.c | 33 |
1 files changed, 33 insertions, 0 deletions
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; |