Commit ee675e87 authored by Jamal Hadi Salim's avatar Jamal Hadi Salim Committed by Stephen Hemminger

xfrm: policy by mark

Add support for SP manipulation by mark
Signed-off-by: default avatarJamal Hadi Salim <hadi@cyberus.ca>
parent e906975a
...@@ -54,8 +54,8 @@ static void usage(void) __attribute__((noreturn)); ...@@ -54,8 +54,8 @@ static void usage(void) __attribute__((noreturn));
static void usage(void) static void usage(void)
{ {
fprintf(stderr, "Usage: ip xfrm policy { add | update } dir DIR SELECTOR [ index INDEX ] [ ptype PTYPE ]\n"); fprintf(stderr, "Usage: ip xfrm policy { add | update } dir DIR SELECTOR [ index INDEX ] [ ptype PTYPE ]\n");
fprintf(stderr, " [ action ACTION ] [ priority PRIORITY ] [ flag FLAG-LIST ] [ LIMIT-LIST ] [ TMPL-LIST ]\n"); fprintf(stderr, " [ action ACTION ] [ priority PRIORITY ] [ flag FLAG-LIST ] [ LIMIT-LIST ] [ TMPL-LIST ] [mark MARK [mask MASK]]\n");
fprintf(stderr, "Usage: ip xfrm policy { delete | get } dir DIR [ SELECTOR | index INDEX ] [ ptype PTYPE ]\n"); fprintf(stderr, "Usage: ip xfrm policy { delete | get } dir DIR [ SELECTOR | index INDEX ] [ ptype PTYPE ] [mark MARK [mask MASK]]\n");
fprintf(stderr, "Usage: ip xfrm policy { deleteall | list } [ dir DIR ] [ SELECTOR ]\n"); fprintf(stderr, "Usage: ip xfrm policy { deleteall | list } [ dir DIR ] [ SELECTOR ]\n");
fprintf(stderr, " [ index INDEX ] [ action ACTION ] [ priority PRIORITY ] [ flag FLAG-LIST ]\n"); fprintf(stderr, " [ index INDEX ] [ action ACTION ] [ priority PRIORITY ] [ flag FLAG-LIST ]\n");
fprintf(stderr, "Usage: ip xfrm policy flush [ ptype PTYPE ]\n"); fprintf(stderr, "Usage: ip xfrm policy flush [ ptype PTYPE ]\n");
...@@ -235,6 +235,7 @@ static int xfrm_policy_modify(int cmd, unsigned flags, int argc, char **argv) ...@@ -235,6 +235,7 @@ static int xfrm_policy_modify(int cmd, unsigned flags, int argc, char **argv)
struct xfrm_userpolicy_type upt; struct xfrm_userpolicy_type upt;
char tmpls_buf[XFRM_TMPLS_BUF_SIZE]; char tmpls_buf[XFRM_TMPLS_BUF_SIZE];
int tmpls_len = 0; int tmpls_len = 0;
struct xfrm_mark mark = {0, 0};
memset(&req, 0, sizeof(req)); memset(&req, 0, sizeof(req));
memset(&upt, 0, sizeof(upt)); memset(&upt, 0, sizeof(upt));
...@@ -258,6 +259,8 @@ static int xfrm_policy_modify(int cmd, unsigned flags, int argc, char **argv) ...@@ -258,6 +259,8 @@ static int xfrm_policy_modify(int cmd, unsigned flags, int argc, char **argv)
NEXT_ARG(); NEXT_ARG();
xfrm_policy_dir_parse(&req.xpinfo.dir, &argc, &argv); xfrm_policy_dir_parse(&req.xpinfo.dir, &argc, &argv);
} else if (strcmp(*argv, "mark") == 0) {
xfrm_parse_mark(&mark, &argc, &argv);
} else if (strcmp(*argv, "index") == 0) { } else if (strcmp(*argv, "index") == 0) {
NEXT_ARG(); NEXT_ARG();
if (get_u32(&req.xpinfo.index, *argv, 0)) if (get_u32(&req.xpinfo.index, *argv, 0))
...@@ -334,6 +337,16 @@ static int xfrm_policy_modify(int cmd, unsigned flags, int argc, char **argv) ...@@ -334,6 +337,16 @@ static int xfrm_policy_modify(int cmd, unsigned flags, int argc, char **argv)
(void *)tmpls_buf, tmpls_len); (void *)tmpls_buf, tmpls_len);
} }
if (mark.m & mark.v) {
int r = addattr_l(&req.n, sizeof(req.buf), XFRMA_MARK,
(void *)&mark, sizeof(mark));
if (r < 0) {
fprintf(stderr, "%s: XFRMA_MARK failed\n",__func__);
exit(1);
}
}
if (rtnl_open_byproto(&rth, 0, NETLINK_XFRM) < 0) if (rtnl_open_byproto(&rth, 0, NETLINK_XFRM) < 0)
exit(1); exit(1);
...@@ -515,6 +528,7 @@ static int xfrm_policy_get_or_delete(int argc, char **argv, int delete, ...@@ -515,6 +528,7 @@ static int xfrm_policy_get_or_delete(int argc, char **argv, int delete,
char *indexp = NULL; char *indexp = NULL;
char *ptypep = NULL; char *ptypep = NULL;
struct xfrm_userpolicy_type upt; struct xfrm_userpolicy_type upt;
struct xfrm_mark mark = {0, 0};
memset(&req, 0, sizeof(req)); memset(&req, 0, sizeof(req));
memset(&upt, 0, sizeof(upt)); memset(&upt, 0, sizeof(upt));
...@@ -532,6 +546,8 @@ static int xfrm_policy_get_or_delete(int argc, char **argv, int delete, ...@@ -532,6 +546,8 @@ static int xfrm_policy_get_or_delete(int argc, char **argv, int delete,
NEXT_ARG(); NEXT_ARG();
xfrm_policy_dir_parse(&req.xpid.dir, &argc, &argv); xfrm_policy_dir_parse(&req.xpid.dir, &argc, &argv);
} else if (strcmp(*argv, "mark") == 0) {
xfrm_parse_mark(&mark, &argc, &argv);
} else if (strcmp(*argv, "index") == 0) { } else if (strcmp(*argv, "index") == 0) {
if (indexp) if (indexp)
duparg("index", *argv); duparg("index", *argv);
...@@ -584,6 +600,15 @@ static int xfrm_policy_get_or_delete(int argc, char **argv, int delete, ...@@ -584,6 +600,15 @@ static int xfrm_policy_get_or_delete(int argc, char **argv, int delete,
if (req.xpid.sel.family == AF_UNSPEC) if (req.xpid.sel.family == AF_UNSPEC)
req.xpid.sel.family = AF_INET; req.xpid.sel.family = AF_INET;
if (mark.m & mark.v) {
int r = addattr_l(&req.n, sizeof(req.buf), XFRMA_MARK,
(void *)&mark, sizeof(mark));
if (r < 0) {
fprintf(stderr, "%s: XFRMA_MARK failed\n",__func__);
exit(1);
}
}
if (rtnl_talk(&rth, &req.n, 0, 0, res_nlbuf, NULL, NULL) < 0) if (rtnl_talk(&rth, &req.n, 0, 0, res_nlbuf, NULL, NULL) < 0)
exit(2); exit(2);
......
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