Message ID | 1291993092-8675-1-git-send-email-opurdila@ixiacom.com |
---|---|
State | Rejected, archived |
Delegated to: | stephen hemminger |
Headers | show |
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. -- To unsubscribe from this list: send the line "unsubscribe netdev" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
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) -- To unsubscribe from this list: send the line "unsubscribe netdev" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
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 -- To unsubscribe from this list: send the line "unsubscribe netdev" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
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) -- To unsubscribe from this list: send the line "unsubscribe netdev" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
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 -- To unsubscribe from this list: send the line "unsubscribe netdev" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
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 -- To unsubscribe from this list: send the line "unsubscribe netdev" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
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 -- To unsubscribe from this list: send the line "unsubscribe netdev" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
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
--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
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. -- To unsubscribe from this list: send the line "unsubscribe netdev" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
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) {
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(-)