netconf: add support for ignore route attribute
Add support for ignore route attribute, and refine the code to use rta_getattr_* function to get attribute value. Signed-off-by: Zhang Shengju <zhangshengju@cmss.chinamobile.com>
This commit is contained in:
parent
c256dcd47c
commit
95c9d0d301
|
|
@ -37,6 +37,11 @@ static void usage(void)
|
||||||
exit(-1);
|
exit(-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void print_onoff(FILE *f, const char *flag, __u32 val)
|
||||||
|
{
|
||||||
|
fprintf(f, "%s %s ", flag, val ? "on" : "off");
|
||||||
|
}
|
||||||
|
|
||||||
static struct rtattr *netconf_rta(struct netconfmsg *ncm)
|
static struct rtattr *netconf_rta(struct netconfmsg *ncm)
|
||||||
{
|
{
|
||||||
return (struct rtattr *)((char *)ncm
|
return (struct rtattr *)((char *)ncm
|
||||||
|
|
@ -84,7 +89,7 @@ int print_netconf(const struct sockaddr_nl *who, struct rtnl_ctrl_data *ctrl,
|
||||||
}
|
}
|
||||||
|
|
||||||
if (tb[NETCONFA_IFINDEX]) {
|
if (tb[NETCONFA_IFINDEX]) {
|
||||||
int *ifindex = (int *)RTA_DATA(tb[NETCONFA_IFINDEX]);
|
int *ifindex = (int *)rta_getattr_str(tb[NETCONFA_IFINDEX]);
|
||||||
|
|
||||||
switch (*ifindex) {
|
switch (*ifindex) {
|
||||||
case NETCONFA_IFINDEX_ALL:
|
case NETCONFA_IFINDEX_ALL:
|
||||||
|
|
@ -100,10 +105,10 @@ int print_netconf(const struct sockaddr_nl *who, struct rtnl_ctrl_data *ctrl,
|
||||||
}
|
}
|
||||||
|
|
||||||
if (tb[NETCONFA_FORWARDING])
|
if (tb[NETCONFA_FORWARDING])
|
||||||
fprintf(fp, "forwarding %s ",
|
print_onoff(fp, "forwarding",
|
||||||
*(int *)RTA_DATA(tb[NETCONFA_FORWARDING])?"on":"off");
|
rta_getattr_u32(tb[NETCONFA_FORWARDING]));
|
||||||
if (tb[NETCONFA_RP_FILTER]) {
|
if (tb[NETCONFA_RP_FILTER]) {
|
||||||
int rp_filter = *(int *)RTA_DATA(tb[NETCONFA_RP_FILTER]);
|
__u32 rp_filter = rta_getattr_u32(tb[NETCONFA_RP_FILTER]);
|
||||||
|
|
||||||
if (rp_filter == 0)
|
if (rp_filter == 0)
|
||||||
fprintf(fp, "rp_filter off ");
|
fprintf(fp, "rp_filter off ");
|
||||||
|
|
@ -115,12 +120,16 @@ int print_netconf(const struct sockaddr_nl *who, struct rtnl_ctrl_data *ctrl,
|
||||||
fprintf(fp, "rp_filter unknown mode ");
|
fprintf(fp, "rp_filter unknown mode ");
|
||||||
}
|
}
|
||||||
if (tb[NETCONFA_MC_FORWARDING])
|
if (tb[NETCONFA_MC_FORWARDING])
|
||||||
fprintf(fp, "mc_forwarding %d ",
|
print_onoff(fp, "mc_forwarding",
|
||||||
*(int *)RTA_DATA(tb[NETCONFA_MC_FORWARDING]));
|
rta_getattr_u32(tb[NETCONFA_MC_FORWARDING]));
|
||||||
|
|
||||||
if (tb[NETCONFA_PROXY_NEIGH])
|
if (tb[NETCONFA_PROXY_NEIGH])
|
||||||
fprintf(fp, "proxy_neigh %s ",
|
print_onoff(fp, "proxy_neigh",
|
||||||
*(int *)RTA_DATA(tb[NETCONFA_PROXY_NEIGH])?"on":"off");
|
rta_getattr_u32(tb[NETCONFA_PROXY_NEIGH]));
|
||||||
|
|
||||||
|
if (tb[NETCONFA_IGNORE_ROUTES_WITH_LINKDOWN])
|
||||||
|
print_onoff(fp, "ignore_routes_with_linkdown",
|
||||||
|
rta_getattr_u32(tb[NETCONFA_IGNORE_ROUTES_WITH_LINKDOWN]));
|
||||||
|
|
||||||
fprintf(fp, "\n");
|
fprintf(fp, "\n");
|
||||||
fflush(fp);
|
fflush(fp);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue