* [PATCH] iproute2: ip: add wilcard support for device matching
@ 2010-12-10 14:58 Octavian Purdila
2010-12-10 16:18 ` Stephen Hemminger
0 siblings, 1 reply; 10+ messages in thread
From: Octavian Purdila @ 2010-12-10 14:58 UTC (permalink / raw)
To: netdev; +Cc: Lucian Adrian Grijincu, Vlad Dogaru, Octavian Purdila
Allow the users to specify a wildcard when selecting a device:
$ ip set link dev dummy* up
We do this by expanding the original command line in multiple lines
which we then feed via a pipe to a forked ip processed run in batch
mode.
Signed-off-by: Octavian Purdila <opurdila@ixiacom.com>
---
ip/ip.c | 70 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 70 insertions(+), 0 deletions(-)
diff --git a/ip/ip.c b/ip/ip.c
index b127d57..2e26488 100644
--- a/ip/ip.c
+++ b/ip/ip.c
@@ -18,6 +18,8 @@
#include <netinet/in.h>
#include <string.h>
#include <errno.h>
+#include <sys/types.h>
+#include <sys/wait.h>
#include "SNAPSHOT.h"
#include "utils.h"
@@ -139,10 +141,72 @@ static int batch(const char *name)
return ret;
}
+int main(int argc, char **argv);
+
+int expand_dev_pattern(int argc, char **argv, int pos)
+{
+ FILE *proc;
+ size_t n, dev_no;
+ char scanf_pattern[64], *line = NULL, *dev_base = argv[pos];
+ int p[2], i;
+ pid_t pid;
+
+ *strchr(dev_base, '*') = 0;
+ snprintf(scanf_pattern, sizeof(scanf_pattern), " %s%%d:", dev_base);
+
+ if (pipe(p) < 0) {
+ fprintf(stderr, "pipe() failed: %s\n", strerror(errno));
+ return -1;
+ }
+
+ pid = fork();
+ switch (pid) {
+ case -1:
+ fprintf(stderr, "fork failed: %s\n", strerror(errno));
+ return -1;
+ case 0:
+ {
+ char *nargv[] = { argv[0], "-b", "-" };
+ int ret;
+
+ dup2(p[0], 0); close(p[0]); close(p[1]);
+ ret = main(3, nargv);
+ exit(ret);
+ }
+ default:
+ dup2(p[1], 1); close(p[0]); close(p[1]);
+ }
+
+ proc = fopen("/proc/net/dev", "r");
+ if (!proc) {
+ fprintf(stderr, "can't open /proc/net/dev\n");
+ return -1;
+ }
+
+ while (getline(&line, &n, proc) > 0) {
+ if (sscanf(line, scanf_pattern, &dev_no) == 1) {
+ for (i = 1; i < argc; i++)
+ if (i != pos)
+ printf("%s ", argv[i]);
+ else
+ printf("%s%d ", dev_base, dev_no);
+ printf("\n");
+ }
+ }
+ free(line);
+
+ fflush(stdout); close(1);
+
+ waitpid(pid, NULL, 0);
+
+ return 0;
+}
int main(int argc, char **argv)
{
char *basename;
+ int i = 0;
+
basename = strrchr(argv[0], '/');
if (basename == NULL)
@@ -150,6 +214,12 @@ int main(int argc, char **argv)
else
basename++;
+ for (i = 1; i < argc - 1; i++) {
+ if (matches(argv[i], "dev") == 0 && strchr(argv[i+1], '*')) {
+ return expand_dev_pattern(argc, argv, i+1);
+ }
+ }
+
while (argc > 1) {
char *opt = argv[1];
if (strcmp(opt,"--") == 0) {
--
1.7.1
^ permalink raw reply related [flat|nested] 10+ messages in thread
* Re: [PATCH] iproute2: ip: add wilcard support for device matching
2010-12-10 14:58 [PATCH] iproute2: ip: add wilcard support for device matching Octavian Purdila
@ 2010-12-10 16:18 ` Stephen Hemminger
2010-12-10 16:32 ` Eric Dumazet
0 siblings, 1 reply; 10+ messages in thread
From: Stephen Hemminger @ 2010-12-10 16:18 UTC (permalink / raw)
To: Octavian Purdila; +Cc: netdev, Lucian Adrian Grijincu, Vlad Dogaru
On Fri, 10 Dec 2010 16:58:12 +0200
Octavian Purdila <opurdila@ixiacom.com> wrote:
> Allow the users to specify a wildcard when selecting a device:
>
> $ ip set link dev dummy* up
>
> We do this by expanding the original command line in multiple lines
> which we then feed via a pipe to a forked ip processed run in batch
> mode.
>
Seems like feature creep. Can't you do this with bash completion
script instead.
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH] iproute2: ip: add wilcard support for device matching
2010-12-10 16:18 ` Stephen Hemminger
@ 2010-12-10 16:32 ` Eric Dumazet
2010-12-10 17:32 ` Octavian Purdila
0 siblings, 1 reply; 10+ messages in thread
From: Eric Dumazet @ 2010-12-10 16:32 UTC (permalink / raw)
To: Stephen Hemminger
Cc: Octavian Purdila, netdev, Lucian Adrian Grijincu, Vlad Dogaru
Le vendredi 10 décembre 2010 à 08:18 -0800, Stephen Hemminger a écrit :
> On Fri, 10 Dec 2010 16:58:12 +0200
> Octavian Purdila <opurdila@ixiacom.com> wrote:
>
> > Allow the users to specify a wildcard when selecting a device:
> >
> > $ ip set link dev dummy* up
> >
> > We do this by expanding the original command line in multiple lines
> > which we then feed via a pipe to a forked ip processed run in batch
> > mode.
> >
>
>
> Seems like feature creep. Can't you do this with bash completion
> script instead.
> -
furthermore, "*" is allowed in a device name
ip link add link bond0 "vlan*" txqueuelen 100 type vlan id 999
$ ifconfig "vlan*"
vlan* Link encap:Ethernet HWaddr 00:1E:0B:EC:D3:D2
BROADCAST MULTICAST MTU:1500 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:100
RX bytes:0 (0.0 b) TX bytes:0 (0.0 b)
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH] iproute2: ip: add wilcard support for device matching
2010-12-10 16:32 ` Eric Dumazet
@ 2010-12-10 17:32 ` Octavian Purdila
2010-12-10 17:42 ` Eric Dumazet
0 siblings, 1 reply; 10+ messages in thread
From: Octavian Purdila @ 2010-12-10 17:32 UTC (permalink / raw)
To: Eric Dumazet
Cc: Stephen Hemminger, netdev, Lucian Adrian Grijincu, Vlad Dogaru
From: Eric Dumazet <eric.dumazet@gmail.com>
Date: Friday 10 December 2010, 18:32:20
> Le vendredi 10 décembre 2010 à 08:18 -0800, Stephen Hemminger a écrit :
> > On Fri, 10 Dec 2010 16:58:12 +0200
> >
> > Octavian Purdila <opurdila@ixiacom.com> wrote:
> > > Allow the users to specify a wildcard when selecting a device:
> > >
> > > $ ip set link dev dummy* up
> > >
> > > We do this by expanding the original command line in multiple lines
> > > which we then feed via a pipe to a forked ip processed run in batch
> > > mode.
> >
> > Seems like feature creep. Can't you do this with bash completion
> > script instead.
This feature would make my life easier so to me its just a nice feature :)
Sure I can do it as a bash completion script but:
- bash does not run everywhere
- having it in iproute would make it available to everyone
- its userspace so the price to pay for a few more lines of code for usability
seems reasonable
- I don't know how scalable you can make the bash completion script
> furthermore, "*" is allowed in a device name
>
> ip link add link bond0 "vlan*" txqueuelen 100 type vlan id 999
>
Would allowing escaping it fix the issue? Like:
ip link add link bond0 "vlan\*" txqueuelen 100 type vlan id 999
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH] iproute2: ip: add wilcard support for device matching
2010-12-10 17:32 ` Octavian Purdila
@ 2010-12-10 17:42 ` Eric Dumazet
2010-12-10 18:06 ` Octavian Purdila
0 siblings, 1 reply; 10+ messages in thread
From: Eric Dumazet @ 2010-12-10 17:42 UTC (permalink / raw)
To: Octavian Purdila
Cc: Stephen Hemminger, netdev, Lucian Adrian Grijincu, Vlad Dogaru
Le vendredi 10 décembre 2010 à 19:32 +0200, Octavian Purdila a écrit :
> Would allowing escaping it fix the issue? Like:
>
> ip link add link bond0 "vlan\*" txqueuelen 100 type vlan id 999
>
Well, same compat problem ;)
$ ip link add link bond0 "vlan\*199" type vlan id 199
$ ifconfig "vlan\*199"
vlan\199 Link encap:Ethernet HWaddr 00:1E:0B:EC:D3:D2
BROADCAST MULTICAST MTU:1500 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:0 (0.0 b) TX bytes:0 (0.0 b)
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH] iproute2: ip: add wilcard support for device matching
2010-12-10 17:42 ` Eric Dumazet
@ 2010-12-10 18:06 ` Octavian Purdila
2010-12-17 13:38 ` jamal
0 siblings, 1 reply; 10+ messages in thread
From: Octavian Purdila @ 2010-12-10 18:06 UTC (permalink / raw)
To: Eric Dumazet
Cc: Stephen Hemminger, netdev, Lucian Adrian Grijincu, Vlad Dogaru
From: Eric Dumazet <eric.dumazet@gmail.com>
Date: Friday 10 December 2010, 19:42:39
> Le vendredi 10 décembre 2010 à 19:32 +0200, Octavian Purdila a écrit :
> > Would allowing escaping it fix the issue? Like:
> >
> > ip link add link bond0 "vlan\*" txqueuelen 100 type vlan id 999
>
> Well, same compat problem ;)
>
> $ ip link add link bond0 "vlan\*199" type vlan id 199
> $ ifconfig "vlan\*199"
:) Then use a special dev keyword like dev* ?
$ ip link set dev* dummy set
Or use a new flag to allow expansion?
$ ip -e link set dev dummy* set
Thanks,
tavi
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH] iproute2: ip: add wilcard support for device matching
2010-12-10 18:06 ` Octavian Purdila
@ 2010-12-17 13:38 ` jamal
2010-12-19 9:32 ` Vlad Dogaru
0 siblings, 1 reply; 10+ messages in thread
From: jamal @ 2010-12-17 13:38 UTC (permalink / raw)
To: Octavian Purdila
Cc: Eric Dumazet, Stephen Hemminger, netdev, Lucian Adrian Grijincu,
Vlad Dogaru
On Fri, 2010-12-10 at 20:06 +0200, Octavian Purdila wrote:
> > $ ip link add link bond0 "vlan\*199" type vlan id 199
> > $ ifconfig "vlan\*199"
>
> :) Then use a special dev keyword like dev* ?
>
> $ ip link set dev* dummy set
>
> Or use a new flag to allow expansion?
>
> $ ip -e link set dev dummy* set
There was something ive always wanted to do but
havent had time. It will cut time in a big way the
user-kernel interaction in precisely your situation.
Add a new general purpose netdev 32 bit tag. You can use this
feature to "group" netdevs. The group "all netdevs" is 0 - which
is the default.
I can group individual dummy interfaces into group 1.
ip link dev dummy0 set group 1
..
..
ip link dev dummy99 set group 1
Then i can send a query to only ifup and ignore
the 1000 vlans that exist.
ip link dev ls group 1
or if i didnt list the group, then group 0 is assumed.
As a warning - this would be a general purpose tag.
So i can use it in conjunction with skb->mark to enable
filtering for example on ingress side with some action.
cheers,
jamal
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH] iproute2: ip: add wilcard support for device matching
2010-12-17 13:38 ` jamal
@ 2010-12-19 9:32 ` Vlad Dogaru
2010-12-21 13:14 ` jamal
0 siblings, 1 reply; 10+ messages in thread
From: Vlad Dogaru @ 2010-12-19 9:32 UTC (permalink / raw)
To: hadi
Cc: Octavian Purdila, Eric Dumazet, Stephen Hemminger, netdev,
Lucian Adrian Grijincu
On 12/17/2010 5:38 AM, jamal wrote:
> On Fri, 2010-12-10 at 20:06 +0200, Octavian Purdila wrote:
>
>>> $ ip link add link bond0 "vlan\*199" type vlan id 199
>>> $ ifconfig "vlan\*199"
>>
>> :) Then use a special dev keyword like dev* ?
>>
>> $ ip link set dev* dummy set
>>
>> Or use a new flag to allow expansion?
>>
>> $ ip -e link set dev dummy* set
>
> There was something ive always wanted to do but
> havent had time. It will cut time in a big way the
> user-kernel interaction in precisely your situation.
>
> Add a new general purpose netdev 32 bit tag. You can use this
> feature to "group" netdevs. The group "all netdevs" is 0 - which
> is the default.
> I can group individual dummy interfaces into group 1.
> ip link dev dummy0 set group 1
> ..
> ..
> ip link dev dummy99 set group 1
>
> Then i can send a query to only ifup and ignore
> the 1000 vlans that exist.
>
> ip link dev ls group 1
>
> or if i didnt list the group, then group 0 is assumed.
I'll try to implement this approach in the next few days.
Vlad
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH] iproute2: ip: add wilcard support for device matching
2010-12-19 9:32 ` Vlad Dogaru
@ 2010-12-21 13:14 ` jamal
2011-01-08 21:10 ` Philip Prindeville
0 siblings, 1 reply; 10+ messages in thread
From: jamal @ 2010-12-21 13:14 UTC (permalink / raw)
To: Vlad Dogaru
Cc: Octavian Purdila, Eric Dumazet, Stephen Hemminger, netdev,
Lucian Adrian Grijincu
On Mon, 2010-12-20 at 11:23 -0800, Vlad Dogaru wrote:
> I'll try to implement this approach in the next few days.
Excellent ;-> Remember, this is general purpose tag, sort
like socket/route/skb->mark. It is upto the administrator to
define its use via policy.
cheers,
jamal
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH] iproute2: ip: add wilcard support for device matching
2010-12-21 13:14 ` jamal
@ 2011-01-08 21:10 ` Philip Prindeville
0 siblings, 0 replies; 10+ messages in thread
From: Philip Prindeville @ 2011-01-08 21:10 UTC (permalink / raw)
To: hadi
Cc: Vlad Dogaru, Octavian Purdila, Eric Dumazet, Stephen Hemminger,
netdev, Lucian Adrian Grijincu
On 12/21/10 5:14 AM, jamal wrote:
> On Mon, 2010-12-20 at 11:23 -0800, Vlad Dogaru wrote:
>
>> I'll try to implement this approach in the next few days.
> Excellent ;-> Remember, this is general purpose tag, sort
> like socket/route/skb->mark. It is upto the administrator to
> define its use via policy.
>
> cheers,
> jamal
Did that end up going anywhere?
There are a lot of cases where matching on "ppp*" would be handy.
^ permalink raw reply [flat|nested] 10+ messages in thread
end of thread, other threads:[~2011-01-08 21:11 UTC | newest]
Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-12-10 14:58 [PATCH] iproute2: ip: add wilcard support for device matching Octavian Purdila
2010-12-10 16:18 ` Stephen Hemminger
2010-12-10 16:32 ` Eric Dumazet
2010-12-10 17:32 ` Octavian Purdila
2010-12-10 17:42 ` Eric Dumazet
2010-12-10 18:06 ` Octavian Purdila
2010-12-17 13:38 ` jamal
2010-12-19 9:32 ` Vlad Dogaru
2010-12-21 13:14 ` jamal
2011-01-08 21:10 ` Philip Prindeville
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).