* iproute, batch-cmds, and mac-vlans.
@ 2010-07-13 4:49 Ben Greear
2010-07-13 5:19 ` Stephen Hemminger
0 siblings, 1 reply; 4+ messages in thread
From: Ben Greear @ 2010-07-13 4:49 UTC (permalink / raw)
To: NetDev
After too much time debugging, I finally realized that the ip
tool was truncating my command because the mac-vlan device name
had a '#' in it.
]# cat /tmp/foo.txt
ru add to 10.99.21.1 iif eth0#0 lookup local pref 11
# IP tool has some hacked up debugging code
]# ip -batch /tmp/foo.txt
argc: 4
arg -:to:-
arg -:iif:-
WARNING: Using TABLE_MAIN in iprule_modify, table_ok: 0 cmd: 32
So, it acts on eth0 instead of eth0#0, and silently ignores the 'lookup local pref 11'.
I understand that it is trying to parse # as comments, but would you
all be interested in a patch that allowed ignoring '#' except
when it is the first non-whitespace character on a line, and maybe
when preceded by whitespace? This would of course have the possibility
of breaking someone's script somewhere, so it could be enabled with
a new command line arg, perhaps.
Thanks,
Ben
--
Ben Greear <greearb@candelatech.com>
Candela Technologies Inc http://www.candelatech.com
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: iproute, batch-cmds, and mac-vlans.
2010-07-13 4:49 iproute, batch-cmds, and mac-vlans Ben Greear
@ 2010-07-13 5:19 ` Stephen Hemminger
2010-07-13 5:32 ` Ben Greear
0 siblings, 1 reply; 4+ messages in thread
From: Stephen Hemminger @ 2010-07-13 5:19 UTC (permalink / raw)
To: Ben Greear; +Cc: NetDev
On Mon, 12 Jul 2010 21:49:20 -0700
Ben Greear <greearb@candelatech.com> wrote:
> After too much time debugging, I finally realized that the ip
> tool was truncating my command because the mac-vlan device name
> had a '#' in it.
>
> ]# cat /tmp/foo.txt
> ru add to 10.99.21.1 iif eth0#0 lookup local pref 11
>
>
> # IP tool has some hacked up debugging code
> ]# ip -batch /tmp/foo.txt
> argc: 4
> arg -:to:-
> arg -:iif:-
> WARNING: Using TABLE_MAIN in iprule_modify, table_ok: 0 cmd: 32
>
>
> So, it acts on eth0 instead of eth0#0, and silently ignores the 'lookup local pref 11'.
>
> I understand that it is trying to parse # as comments, but would you
> all be interested in a patch that allowed ignoring '#' except
> when it is the first non-whitespace character on a line, and maybe
> when preceded by whitespace? This would of course have the possibility
> of breaking someone's script somewhere, so it could be enabled with
> a new command line arg, perhaps.
Putting # in device name just sounds like a bad idea.
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: iproute, batch-cmds, and mac-vlans.
2010-07-13 5:19 ` Stephen Hemminger
@ 2010-07-13 5:32 ` Ben Greear
2010-07-13 15:41 ` Stephen Hemminger
0 siblings, 1 reply; 4+ messages in thread
From: Ben Greear @ 2010-07-13 5:32 UTC (permalink / raw)
To: Stephen Hemminger; +Cc: NetDev
On 07/12/2010 10:19 PM, Stephen Hemminger wrote:
> On Mon, 12 Jul 2010 21:49:20 -0700
> Ben Greear<greearb@candelatech.com> wrote:
>
>> After too much time debugging, I finally realized that the ip
>> tool was truncating my command because the mac-vlan device name
>> had a '#' in it.
>>
>> ]# cat /tmp/foo.txt
>> ru add to 10.99.21.1 iif eth0#0 lookup local pref 11
>>
>>
>> # IP tool has some hacked up debugging code
>> ]# ip -batch /tmp/foo.txt
>> argc: 4
>> arg -:to:-
>> arg -:iif:-
>> WARNING: Using TABLE_MAIN in iprule_modify, table_ok: 0 cmd: 32
>>
>>
>> So, it acts on eth0 instead of eth0#0, and silently ignores the 'lookup local pref 11'.
>>
>> I understand that it is trying to parse # as comments, but would you
>> all be interested in a patch that allowed ignoring '#' except
>> when it is the first non-whitespace character on a line, and maybe
>> when preceded by whitespace? This would of course have the possibility
>> of breaking someone's script somewhere, so it could be enabled with
>> a new command line arg, perhaps.
>
> Putting # in device name just sounds like a bad idea.
It's been the standard naming for mac-vlans since we started supporting them.
In case you change your mind, this patch seems to work..though I can't figure out
how to trigger the second bit of code in the while loop, so it may not be right.
I'll move my iproute2 tree to github in case someone else wants to give
it a try.
diff --git a/lib/utils.c b/lib/utils.c
index a60d884..ad8e1ac 100644
--- a/lib/utils.c
+++ b/lib/utils.c
@@ -25,7 +25,7 @@
#include <linux/pkt_sched.h>
#include <time.h>
#include <sys/time.h>
-
+#include <ctype.h>
#include "utils.h"
@@ -708,8 +708,23 @@ ssize_t getcmdline(char **linep, size_t *lenp, FILE *in)
++cmdlineno;
cp = strchr(*linep, '#');
- if (cp)
- *cp = '\0';
+
+ /* We don't want to treat the # in the middle of a word as
+ * a comment..makes batch commands dealing with mac-vlans: eth0#1
+ * silently do the wrong thing. So, tighten up the # syntax a bit.
+ *
+ * # at start of line comments rest of line
+ * # preceded by a whitespace character comments rest of line.
+ */
+ while (cp) {
+ if (cp &&
+ ((cp == *linep) /* starts line */
+ || ((cp > *linep) && isspace(*(cp - 1))))) { /* follows space */
+ *cp = '\0';
+ break;
+ }
+ cp = strchr(cp+1, '#');
+ }
while ((cp = strstr(*linep, "\\\n")) != NULL) {
char *line1 = NULL;
@@ -725,9 +740,16 @@ ssize_t getcmdline(char **linep, size_t *lenp, FILE *in)
*cp = 0;
cp = strchr(line1, '#');
- if (cp)
- *cp = '\0';
-
+ while (cp) {
+ if (cp &&
+ ((cp == line1) /* starts line */
+ || ((cp > line1) && isspace(*(cp - 1))))) { /* follows space */
+ *cp = '\0';
+ break;
+ }
+ cp = strchr(cp+1, '#');
+ }
+
*lenp = strlen(*linep) + strlen(line1) + 1;
*linep = realloc(*linep, *lenp);
if (!*linep) {
> --
> 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
--
Ben Greear <greearb@candelatech.com>
Candela Technologies Inc http://www.candelatech.com
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: iproute, batch-cmds, and mac-vlans.
2010-07-13 5:32 ` Ben Greear
@ 2010-07-13 15:41 ` Stephen Hemminger
0 siblings, 0 replies; 4+ messages in thread
From: Stephen Hemminger @ 2010-07-13 15:41 UTC (permalink / raw)
To: Ben Greear; +Cc: NetDev
On Mon, 12 Jul 2010 22:32:53 -0700
Ben Greear <greearb@candelatech.com> wrote:
> On 07/12/2010 10:19 PM, Stephen Hemminger wrote:
> > On Mon, 12 Jul 2010 21:49:20 -0700
> > Ben Greear<greearb@candelatech.com> wrote:
> >
> >> After too much time debugging, I finally realized that the ip
> >> tool was truncating my command because the mac-vlan device name
> >> had a '#' in it.
> >>
> >> ]# cat /tmp/foo.txt
> >> ru add to 10.99.21.1 iif eth0#0 lookup local pref 11
> >>
> >>
> >> # IP tool has some hacked up debugging code
> >> ]# ip -batch /tmp/foo.txt
> >> argc: 4
> >> arg -:to:-
> >> arg -:iif:-
> >> WARNING: Using TABLE_MAIN in iprule_modify, table_ok: 0 cmd: 32
> >>
> >>
> >> So, it acts on eth0 instead of eth0#0, and silently ignores the 'lookup local pref 11'.
> >>
> >> I understand that it is trying to parse # as comments, but would you
> >> all be interested in a patch that allowed ignoring '#' except
> >> when it is the first non-whitespace character on a line, and maybe
> >> when preceded by whitespace? This would of course have the possibility
> >> of breaking someone's script somewhere, so it could be enabled with
> >> a new command line arg, perhaps.
> >
> > Putting # in device name just sounds like a bad idea.
>
> It's been the standard naming for mac-vlans since we started supporting them.
>
> In case you change your mind, this patch seems to work..though I can't figure out
> how to trigger the second bit of code in the while loop, so it may not be right.
>
> I'll move my iproute2 tree to github in case someone else wants to give
> it a try.
I am going to put a more restrictive version of getcmdline(). Comments
will only be allowed at start of line.
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2010-07-13 15:41 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-07-13 4:49 iproute, batch-cmds, and mac-vlans Ben Greear
2010-07-13 5:19 ` Stephen Hemminger
2010-07-13 5:32 ` Ben Greear
2010-07-13 15:41 ` Stephen Hemminger
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).