Commit 4a9608e6 authored by Timo Teräs's avatar Timo Teräs Committed by Stephen Hemminger

iproute2: support xfrm upper protocol gre key

Similar to tunnel side: accept dotted-quad and number formats.
Use regular number for printing the key.
Signed-off-by: default avatarTimo Teräs <timo.teras@iki.fi>
parent 6f4f7c46
...@@ -483,6 +483,12 @@ void xfrm_selector_print(struct xfrm_selector *sel, __u16 family, ...@@ -483,6 +483,12 @@ void xfrm_selector_print(struct xfrm_selector *sel, __u16 family,
if (sel->dport_mask) if (sel->dport_mask)
fprintf(fp, "code %u ", ntohs(sel->dport)); fprintf(fp, "code %u ", ntohs(sel->dport));
break; break;
case IPPROTO_GRE:
if (sel->sport_mask || sel->dport_mask)
fprintf(fp, "key %u ",
(((__u32)ntohs(sel->sport)) << 16) +
ntohs(sel->dport));
break;
case IPPROTO_MH: case IPPROTO_MH:
if (sel->sport_mask) if (sel->sport_mask)
fprintf(fp, "type %u ", ntohs(sel->sport)); fprintf(fp, "type %u ", ntohs(sel->sport));
...@@ -1086,6 +1092,7 @@ static int xfrm_selector_upspec_parse(struct xfrm_selector *sel, ...@@ -1086,6 +1092,7 @@ static int xfrm_selector_upspec_parse(struct xfrm_selector *sel,
char *dportp = NULL; char *dportp = NULL;
char *typep = NULL; char *typep = NULL;
char *codep = NULL; char *codep = NULL;
char *grekey = NULL;
while (1) { while (1) {
if (strcmp(*argv, "proto") == 0) { if (strcmp(*argv, "proto") == 0) {
...@@ -1162,6 +1169,29 @@ static int xfrm_selector_upspec_parse(struct xfrm_selector *sel, ...@@ -1162,6 +1169,29 @@ static int xfrm_selector_upspec_parse(struct xfrm_selector *sel,
filter.upspec_dport_mask = XFRM_FILTER_MASK_FULL; filter.upspec_dport_mask = XFRM_FILTER_MASK_FULL;
} else if (strcmp(*argv, "key") == 0) {
unsigned uval;
grekey = *argv;
NEXT_ARG();
if (strchr(*argv, '.'))
uval = htonl(get_addr32(*argv));
else {
if (get_unsigned(&uval, *argv, 0)<0) {
fprintf(stderr, "invalid value of \"key\"\n");
exit(-1);
}
}
sel->sport = htons(uval >> 16);
sel->dport = htons(uval & 0xffff);
sel->sport_mask = ~((__u16)0);
sel->dport_mask = ~((__u16)0);
filter.upspec_dport_mask = XFRM_FILTER_MASK_FULL;
} else { } else {
PREV_ARG(); /* back track */ PREV_ARG(); /* back track */
break; break;
...@@ -1196,6 +1226,15 @@ static int xfrm_selector_upspec_parse(struct xfrm_selector *sel, ...@@ -1196,6 +1226,15 @@ static int xfrm_selector_upspec_parse(struct xfrm_selector *sel,
exit(1); exit(1);
} }
} }
if (grekey) {
switch (sel->proto) {
case IPPROTO_GRE:
break;
default:
fprintf(stderr, "\"key\" is invalid with proto=%s\n", strxf_proto(sel->proto));
exit(1);
}
}
*argcp = argc; *argcp = argc;
*argvp = argv; *argvp = argv;
......
...@@ -66,7 +66,8 @@ static void usage(void) ...@@ -66,7 +66,8 @@ static void usage(void)
fprintf(stderr, "SELECTOR := src ADDR[/PLEN] dst ADDR[/PLEN] [ UPSPEC ] [ dev DEV ]\n"); fprintf(stderr, "SELECTOR := src ADDR[/PLEN] dst ADDR[/PLEN] [ UPSPEC ] [ dev DEV ]\n");
fprintf(stderr, "UPSPEC := proto PROTO [ [ sport PORT ] [ dport PORT ] |\n"); fprintf(stderr, "UPSPEC := proto PROTO [ [ sport PORT ] [ dport PORT ] |\n");
fprintf(stderr, " [ type NUMBER ] [ code NUMBER ] ]\n"); fprintf(stderr, " [ type NUMBER ] [ code NUMBER ] |\n");
fprintf(stderr, " [ key { DOTTED_QUAD | NUMBER } ] ]\n");
//fprintf(stderr, "DEV - device name(default=none)\n"); //fprintf(stderr, "DEV - device name(default=none)\n");
......
...@@ -547,7 +547,10 @@ throw " | " unreachable " | " prohibit " | " blackhole " | " nat " ]" ...@@ -547,7 +547,10 @@ throw " | " unreachable " | " prohibit " | " blackhole " | " nat " ]"
.RB " [ " type .RB " [ " type
.IR NUMBER " ] " .IR NUMBER " ] "
.RB " [ " code .RB " [ " code
.IR NUMBER " ]] " .IR NUMBER " ] | "
.br
.RB " [ " key
.IR KEY " ]] "
.ti -8 .ti -8
.IR LIMIT-LIST " := [ " LIMIT-LIST " ] |" .IR LIMIT-LIST " := [ " LIMIT-LIST " ] |"
...@@ -642,7 +645,10 @@ throw " | " unreachable " | " prohibit " | " blackhole " | " nat " ]" ...@@ -642,7 +645,10 @@ throw " | " unreachable " | " prohibit " | " blackhole " | " nat " ]"
.RB " [ " type .RB " [ " type
.IR NUMBER " ] " .IR NUMBER " ] "
.RB " [ " code .RB " [ " code
.IR NUMBER " ] ] " .IR NUMBER " ] | "
.br
.RB " [ " key
.IR KEY " ] ] "
.ti -8 .ti -8
.IR ACTION " := " .IR ACTION " := "
...@@ -2487,9 +2493,11 @@ is defined by source port ...@@ -2487,9 +2493,11 @@ is defined by source port
.BR sport ", " .BR sport ", "
destination port destination port
.BR dport ", " type .BR dport ", " type
as number and as number,
.B code .B code
also number. also number and
.BR key
as dotted-quad or number.
.TP .TP
.BI dev " DEV " .BI dev " DEV "
...@@ -2556,11 +2564,10 @@ and the other choice is ...@@ -2556,11 +2564,10 @@ and the other choice is
.TP .TP
.IR UPSPEC .IR UPSPEC
is specified by is specified by
.BR sport ", " .BR sport " and " dport " (for UDP/TCP), "
.BR dport ", " type .BR type " and " code " (for ICMP; as number) or "
and .BR key " (for GRE; as dotted-quad or number)."
.B code .
(NUMBER).
.SS ip xfrm monitor - is used for listing all objects or defined group of them. .SS ip xfrm monitor - is used for listing all objects or defined group of them.
The The
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment