* [PATCH] add vif using local interface index instead of IP
@ 2009-09-16 15:53 Ilia K.
2009-10-07 8:23 ` David Miller
0 siblings, 1 reply; 2+ messages in thread
From: Ilia K. @ 2009-09-16 15:53 UTC (permalink / raw)
To: Octavian Purdila; +Cc: David Miller, netdev
[-- Attachment #1: Type: text/plain, Size: 1426 bytes --]
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>
[-- Attachment #2: vif_add.patch --]
[-- Type: text/x-diff, Size: 1634 bytes --]
=== modified file 'include/linux/mroute.h'
--- old/include/linux/mroute.h 2009-08-10 11:17:32 +0000
+++ new/include/linux/mroute.h 2009-09-08 06:58:46 +0000
@@ -59,13 +59,18 @@
unsigned char vifc_flags; /* VIFF_ flags */
unsigned char vifc_threshold; /* ttl limit */
unsigned int vifc_rate_limit; /* Rate limiter values (NI) */
- struct in_addr vifc_lcl_addr; /* Our address */
+ union {
+ struct in_addr vifc_lcl_addr; /* Local interface address */
+ int vifc_lcl_ifindex; /* Local interface index */
+ };
struct in_addr vifc_rmt_addr; /* IPIP tunnel addr */
};
-#define VIFF_TUNNEL 0x1 /* IPIP tunnel */
-#define VIFF_SRCRT 0x2 /* NI */
-#define VIFF_REGISTER 0x4 /* register vif */
+#define VIFF_TUNNEL 0x1 /* IPIP tunnel */
+#define VIFF_SRCRT 0x2 /* NI */
+#define VIFF_REGISTER 0x4 /* register vif */
+#define VIFF_USE_IFINDEX 0x8 /* use vifc_lcl_ifindex instead of
+ vifc_lcl_addr to find an interface */
/*
* Cache manipulation structures for mrouted and PIMd
=== modified file 'net/ipv4/ipmr.c'
--- old/net/ipv4/ipmr.c 2009-08-10 11:17:32 +0000
+++ new/net/ipv4/ipmr.c 2009-09-08 06:34:21 +0000
@@ -470,8 +470,18 @@
return err;
}
break;
+
+ case VIFF_USE_IFINDEX:
case 0:
- dev = ip_dev_find(net, vifc->vifc_lcl_addr.s_addr);
+ if (vifc->vifc_flags == VIFF_USE_IFINDEX) {
+ dev = dev_get_by_index(net, vifc->vifc_lcl_ifindex);
+ if (dev && dev->ip_ptr == NULL) {
+ dev_put(dev);
+ return -EADDRNOTAVAIL;
+ }
+ } else
+ dev = ip_dev_find(net, vifc->vifc_lcl_addr.s_addr);
+
if (!dev)
return -EADDRNOTAVAIL;
err = dev_set_allmulti(dev, 1);
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH] add vif using local interface index instead of IP
2009-09-16 15:53 [PATCH] add vif using local interface index instead of IP Ilia K.
@ 2009-10-07 8:23 ` David Miller
0 siblings, 0 replies; 2+ messages in thread
From: David Miller @ 2009-10-07 8:23 UTC (permalink / raw)
To: mail4ilia; +Cc: opurdila, netdev
From: "Ilia K." <mail4ilia@gmail.com>
Date: Wed, 16 Sep 2009 18:53:07 +0300
> When routing daemon wants to enable forwarding of multicast traffic it
> performs something like:
...
> 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:
...
> Signed-off-by: Ilia K. <mail4ilia@gmail.com>
Applied, thank you.
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2009-10-07 8:23 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-09-16 15:53 [PATCH] add vif using local interface index instead of IP Ilia K.
2009-10-07 8:23 ` David Miller
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).