summaryrefslogtreecommitdiff
path: root/ip/iprule.c
diff options
context:
space:
mode:
authorStephen Hemminger <stephen@networkplumber.org>2016-03-21 11:52:19 -0700
committerStephen Hemminger <stephen@networkplumber.org>2016-03-21 11:52:19 -0700
commit56f5daac98da0c405fdbc52f04afd5de82404bce (patch)
tree41ab87fe3c21871858e9014bfbef2edf9f3258ce /ip/iprule.c
parent32a121cba257954963fbdd56a1c4567c2efc779a (diff)
ip: code cleanup
Run all the ip code through checkpatch and have it fix the obvious stuff.
Diffstat (limited to 'ip/iprule.c')
-rw-r--r--ip/iprule.c24
1 files changed, 19 insertions, 5 deletions
diff --git a/ip/iprule.c b/ip/iprule.c
index 7e3b38b6..dc45c6b4 100644
--- a/ip/iprule.c
+++ b/ip/iprule.c
@@ -51,13 +51,14 @@ static void usage(void)
int print_rule(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg)
{
- FILE *fp = (FILE*)arg;
+ FILE *fp = (FILE *)arg;
struct rtmsg *r = NLMSG_DATA(n);
int len = n->nlmsg_len;
int host_len = -1;
__u32 table;
- struct rtattr * tb[FRA_MAX+1];
+ struct rtattr *tb[FRA_MAX+1];
char abuf[256];
+
SPRINT_BUF(b1);
if (n->nlmsg_type != RTM_NEWRULE && n->nlmsg_type != RTM_DELRULE)
@@ -75,7 +76,7 @@ int print_rule(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg)
fprintf(fp, "Deleted ");
if (tb[FRA_PRIORITY])
- fprintf(fp, "%u:\t", *(unsigned*)RTA_DATA(tb[FRA_PRIORITY]));
+ fprintf(fp, "%u:\t", *(unsigned *)RTA_DATA(tb[FRA_PRIORITY]));
else
fprintf(fp, "0:\t");
@@ -157,12 +158,14 @@ int print_rule(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg)
if (tb[FRA_SUPPRESS_PREFIXLEN]) {
int pl = rta_getattr_u32(tb[FRA_SUPPRESS_PREFIXLEN]);
+
if (pl != -1) {
fprintf(fp, "suppress_prefixlength %d ", pl);
}
}
if (tb[FRA_SUPPRESS_IFGROUP]) {
int group = rta_getattr_u32(tb[FRA_SUPPRESS_IFGROUP]);
+
if (group != -1) {
SPRINT_BUF(b1);
fprintf(fp, "suppress_ifgroup %s ", rtnl_group_n2a(group, b1, sizeof(b1)));
@@ -173,6 +176,7 @@ int print_rule(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg)
if (tb[FRA_FLOW]) {
__u32 to = rta_getattr_u32(tb[FRA_FLOW]);
__u32 from = to>>16;
+
to &= 0xFFFF;
if (from) {
fprintf(fp, "realms %s/",
@@ -326,7 +330,7 @@ static int iprule_modify(int cmd, int argc, char **argv)
struct {
struct nlmsghdr n;
struct rtmsg r;
- char buf[1024];
+ char buf[1024];
} req;
memset(&req, 0, sizeof(req));
@@ -351,12 +355,14 @@ static int iprule_modify(int cmd, int argc, char **argv)
req.r.rtm_flags |= FIB_RULE_INVERT;
} else if (strcmp(*argv, "from") == 0) {
inet_prefix dst;
+
NEXT_ARG();
get_prefix(&dst, *argv, req.r.rtm_family);
req.r.rtm_src_len = dst.bitlen;
addattr_l(&req.n, sizeof(req), FRA_SRC, &dst.data, dst.bytelen);
} else if (strcmp(*argv, "to") == 0) {
inet_prefix dst;
+
NEXT_ARG();
get_prefix(&dst, *argv, req.r.rtm_family);
req.r.rtm_dst_len = dst.bitlen;
@@ -365,6 +371,7 @@ static int iprule_modify(int cmd, int argc, char **argv)
matches(*argv, "order") == 0 ||
matches(*argv, "priority") == 0) {
__u32 pref;
+
NEXT_ARG();
if (get_u32(&pref, *argv, 0))
invarg("preference value is invalid\n", *argv);
@@ -372,6 +379,7 @@ static int iprule_modify(int cmd, int argc, char **argv)
} else if (strcmp(*argv, "tos") == 0 ||
matches(*argv, "dsfield") == 0) {
__u32 tos;
+
NEXT_ARG();
if (rtnl_dsfield_a2n(&tos, *argv))
invarg("TOS value is invalid\n", *argv);
@@ -379,6 +387,7 @@ static int iprule_modify(int cmd, int argc, char **argv)
} else if (strcmp(*argv, "fwmark") == 0) {
char *slash;
__u32 fwmark, fwmask;
+
NEXT_ARG();
if ((slash = strchr(*argv, '/')) != NULL)
*slash = '\0';
@@ -392,6 +401,7 @@ static int iprule_modify(int cmd, int argc, char **argv)
}
} else if (matches(*argv, "realms") == 0) {
__u32 realm;
+
NEXT_ARG();
if (get_rt_realms_or_raw(&realm, *argv))
invarg("invalid realms\n", *argv);
@@ -399,6 +409,7 @@ static int iprule_modify(int cmd, int argc, char **argv)
} else if (matches(*argv, "table") == 0 ||
strcmp(*argv, "lookup") == 0) {
__u32 tid;
+
NEXT_ARG();
if (rtnl_rttable_a2n(&tid, *argv))
invarg("invalid table ID\n", *argv);
@@ -412,6 +423,7 @@ static int iprule_modify(int cmd, int argc, char **argv)
} else if (matches(*argv, "suppress_prefixlength") == 0 ||
strcmp(*argv, "sup_pl") == 0) {
int pl;
+
NEXT_ARG();
if (get_s32(&pl, *argv, 0) || pl < 0)
invarg("suppress_prefixlength value is invalid\n", *argv);
@@ -420,6 +432,7 @@ static int iprule_modify(int cmd, int argc, char **argv)
strcmp(*argv, "sup_group") == 0) {
NEXT_ARG();
int group;
+
if (rtnl_group_a2n(&group, *argv))
invarg("Invalid \"suppress_ifgroup\" value\n", *argv);
addattr32(&req.n, sizeof(req), FRA_SUPPRESS_IFGROUP, group);
@@ -446,6 +459,7 @@ static int iprule_modify(int cmd, int argc, char **argv)
usage();
else if (matches(*argv, "goto") == 0) {
__u32 target;
+
type = FR_ACT_GOTO;
NEXT_ARG();
if (get_u32(&target, *argv, 0))
@@ -480,7 +494,7 @@ static int flush_rule(const struct sockaddr_nl *who, struct nlmsghdr *n, void *a
struct rtnl_handle rth2;
struct rtmsg *r = NLMSG_DATA(n);
int len = n->nlmsg_len;
- struct rtattr * tb[FRA_MAX+1];
+ struct rtattr *tb[FRA_MAX+1];
len -= NLMSG_LENGTH(sizeof(*r));
if (len < 0)