aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorIlia K <mail4ilia@gmail.com>2009-09-16 01:53:07 -0400
committerDavid S. Miller <davem@davemloft.net>2009-10-07 03:48:41 -0400
commitee5e81f00051b5c373c8de16e3604fd6d3be699e (patch)
treef10ed0120d1669cf903752c3595fbb4b213795f5
parent7bb5fdc2fb021e32703ed1ff0269876bde1fa962 (diff)
add vif using local interface index instead of IP
When routing daemon wants to enable forwarding of multicast traffic it performs something like: struct vifctl vc = { .vifc_vifi = 1, .vifc_flags = 0, .vifc_threshold = 1, .vifc_rate_limit = 0, .vifc_lcl_addr = ip, /* <--- ip address of physical interface, e.g. eth0 */ .vifc_rmt_addr.s_addr = htonl(INADDR_ANY), }; setsockopt(fd, IPPROTO_IP, MRT_ADD_VIF, &vc, sizeof(vc)); This leads (in the kernel) to calling vif_add() function call which search the (physical) device using assigned IP address: dev = ip_dev_find(net, vifc->vifc_lcl_addr.s_addr); The current API (struct vifctl) does not allow to specify an interface other way than using it's IP, and if there are more than a single interface with specified IP only the first one will be found. The attached patch (against 2.6.30.4) allows to specify an interface by its index, instead of IP address: struct vifctl vc = { .vifc_vifi = 1, .vifc_flags = VIFF_USE_IFINDEX, /* NEW */ .vifc_threshold = 1, .vifc_rate_limit = 0, .vifc_lcl_ifindex = if_nametoindex("eth0"), /* NEW */ .vifc_rmt_addr.s_addr = htonl(INADDR_ANY), }; setsockopt(fd, IPPROTO_IP, MRT_ADD_VIF, &vc, sizeof(vc)); Signed-off-by: Ilia K. <mail4ilia@gmail.com> === modified file 'include/linux/mroute.h' Signed-off-by: David S. Miller <davem@davemloft.net>
-rw-r--r--include/linux/mroute.h13
-rw-r--r--net/ipv4/ipmr.c12
2 files changed, 20 insertions, 5 deletions
diff --git a/include/linux/mroute.h b/include/linux/mroute.h
index 08bc776d05e2..d5f69151f692 100644
--- a/include/linux/mroute.h
+++ b/include/linux/mroute.h
@@ -59,13 +59,18 @@ struct vifctl {
59 unsigned char vifc_flags; /* VIFF_ flags */ 59 unsigned char vifc_flags; /* VIFF_ flags */
60 unsigned char vifc_threshold; /* ttl limit */ 60 unsigned char vifc_threshold; /* ttl limit */
61 unsigned int vifc_rate_limit; /* Rate limiter values (NI) */ 61 unsigned int vifc_rate_limit; /* Rate limiter values (NI) */
62 struct in_addr vifc_lcl_addr; /* Our address */ 62 union {
63 struct in_addr vifc_lcl_addr; /* Local interface address */
64 int vifc_lcl_ifindex; /* Local interface index */
65 };
63 struct in_addr vifc_rmt_addr; /* IPIP tunnel addr */ 66 struct in_addr vifc_rmt_addr; /* IPIP tunnel addr */
64}; 67};
65 68
66#define VIFF_TUNNEL 0x1 /* IPIP tunnel */ 69#define VIFF_TUNNEL 0x1 /* IPIP tunnel */
67#define VIFF_SRCRT 0x2 /* NI */ 70#define VIFF_SRCRT 0x2 /* NI */
68#define VIFF_REGISTER 0x4 /* register vif */ 71#define VIFF_REGISTER 0x4 /* register vif */
72#define VIFF_USE_IFINDEX 0x8 /* use vifc_lcl_ifindex instead of
73 vifc_lcl_addr to find an interface */
69 74
70/* 75/*
71 * Cache manipulation structures for mrouted and PIMd 76 * Cache manipulation structures for mrouted and PIMd
diff --git a/net/ipv4/ipmr.c b/net/ipv4/ipmr.c
index 630a56df7b47..c757f0b4b74c 100644
--- a/net/ipv4/ipmr.c
+++ b/net/ipv4/ipmr.c
@@ -469,8 +469,18 @@ static int vif_add(struct net *net, struct vifctl *vifc, int mrtsock)
469 return err; 469 return err;
470 } 470 }
471 break; 471 break;
472
473 case VIFF_USE_IFINDEX:
472 case 0: 474 case 0:
473 dev = ip_dev_find(net, vifc->vifc_lcl_addr.s_addr); 475 if (vifc->vifc_flags == VIFF_USE_IFINDEX) {
476 dev = dev_get_by_index(net, vifc->vifc_lcl_ifindex);
477 if (dev && dev->ip_ptr == NULL) {
478 dev_put(dev);
479 return -EADDRNOTAVAIL;
480 }
481 } else
482 dev = ip_dev_find(net, vifc->vifc_lcl_addr.s_addr);
483
474 if (!dev) 484 if (!dev)
475 return -EADDRNOTAVAIL; 485 return -EADDRNOTAVAIL;
476 err = dev_set_allmulti(dev, 1); 486 err = dev_set_allmulti(dev, 1);