Commit 136ba622 authored by Zhang Shengju's avatar Zhang Shengju Committed by David S. Miller

netconf: add macro to represent all attributes

This patch adds macro NETCONFA_ALL to represent all type of netconf
attributes for IPv4 and IPv6.
Signed-off-by: default avatarZhang Shengju <zhangshengju@cmss.chinamobile.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 39d2adeb
...@@ -19,6 +19,7 @@ enum { ...@@ -19,6 +19,7 @@ enum {
__NETCONFA_MAX __NETCONFA_MAX
}; };
#define NETCONFA_MAX (__NETCONFA_MAX - 1) #define NETCONFA_MAX (__NETCONFA_MAX - 1)
#define NETCONFA_ALL -1
#define NETCONFA_IFINDEX_ALL -1 #define NETCONFA_IFINDEX_ALL -1
#define NETCONFA_IFINDEX_DEFAULT -2 #define NETCONFA_IFINDEX_DEFAULT -2
......
...@@ -1753,17 +1753,20 @@ static int inet_netconf_msgsize_devconf(int type) ...@@ -1753,17 +1753,20 @@ static int inet_netconf_msgsize_devconf(int type)
{ {
int size = NLMSG_ALIGN(sizeof(struct netconfmsg)) int size = NLMSG_ALIGN(sizeof(struct netconfmsg))
+ nla_total_size(4); /* NETCONFA_IFINDEX */ + nla_total_size(4); /* NETCONFA_IFINDEX */
bool all = false;
/* type -1 is used for ALL */ if (type == NETCONFA_ALL)
if (type == -1 || type == NETCONFA_FORWARDING) all = true;
if (all || type == NETCONFA_FORWARDING)
size += nla_total_size(4); size += nla_total_size(4);
if (type == -1 || type == NETCONFA_RP_FILTER) if (all || type == NETCONFA_RP_FILTER)
size += nla_total_size(4); size += nla_total_size(4);
if (type == -1 || type == NETCONFA_MC_FORWARDING) if (all || type == NETCONFA_MC_FORWARDING)
size += nla_total_size(4); size += nla_total_size(4);
if (type == -1 || type == NETCONFA_PROXY_NEIGH) if (all || type == NETCONFA_PROXY_NEIGH)
size += nla_total_size(4); size += nla_total_size(4);
if (type == -1 || type == NETCONFA_IGNORE_ROUTES_WITH_LINKDOWN) if (all || type == NETCONFA_IGNORE_ROUTES_WITH_LINKDOWN)
size += nla_total_size(4); size += nla_total_size(4);
return size; return size;
...@@ -1776,36 +1779,39 @@ static int inet_netconf_fill_devconf(struct sk_buff *skb, int ifindex, ...@@ -1776,36 +1779,39 @@ static int inet_netconf_fill_devconf(struct sk_buff *skb, int ifindex,
{ {
struct nlmsghdr *nlh; struct nlmsghdr *nlh;
struct netconfmsg *ncm; struct netconfmsg *ncm;
bool all = false;
nlh = nlmsg_put(skb, portid, seq, event, sizeof(struct netconfmsg), nlh = nlmsg_put(skb, portid, seq, event, sizeof(struct netconfmsg),
flags); flags);
if (!nlh) if (!nlh)
return -EMSGSIZE; return -EMSGSIZE;
if (type == NETCONFA_ALL)
all = true;
ncm = nlmsg_data(nlh); ncm = nlmsg_data(nlh);
ncm->ncm_family = AF_INET; ncm->ncm_family = AF_INET;
if (nla_put_s32(skb, NETCONFA_IFINDEX, ifindex) < 0) if (nla_put_s32(skb, NETCONFA_IFINDEX, ifindex) < 0)
goto nla_put_failure; goto nla_put_failure;
/* type -1 is used for ALL */ if ((all || type == NETCONFA_FORWARDING) &&
if ((type == -1 || type == NETCONFA_FORWARDING) &&
nla_put_s32(skb, NETCONFA_FORWARDING, nla_put_s32(skb, NETCONFA_FORWARDING,
IPV4_DEVCONF(*devconf, FORWARDING)) < 0) IPV4_DEVCONF(*devconf, FORWARDING)) < 0)
goto nla_put_failure; goto nla_put_failure;
if ((type == -1 || type == NETCONFA_RP_FILTER) && if ((all || type == NETCONFA_RP_FILTER) &&
nla_put_s32(skb, NETCONFA_RP_FILTER, nla_put_s32(skb, NETCONFA_RP_FILTER,
IPV4_DEVCONF(*devconf, RP_FILTER)) < 0) IPV4_DEVCONF(*devconf, RP_FILTER)) < 0)
goto nla_put_failure; goto nla_put_failure;
if ((type == -1 || type == NETCONFA_MC_FORWARDING) && if ((all || type == NETCONFA_MC_FORWARDING) &&
nla_put_s32(skb, NETCONFA_MC_FORWARDING, nla_put_s32(skb, NETCONFA_MC_FORWARDING,
IPV4_DEVCONF(*devconf, MC_FORWARDING)) < 0) IPV4_DEVCONF(*devconf, MC_FORWARDING)) < 0)
goto nla_put_failure; goto nla_put_failure;
if ((type == -1 || type == NETCONFA_PROXY_NEIGH) && if ((all || type == NETCONFA_PROXY_NEIGH) &&
nla_put_s32(skb, NETCONFA_PROXY_NEIGH, nla_put_s32(skb, NETCONFA_PROXY_NEIGH,
IPV4_DEVCONF(*devconf, PROXY_ARP)) < 0) IPV4_DEVCONF(*devconf, PROXY_ARP)) < 0)
goto nla_put_failure; goto nla_put_failure;
if ((type == -1 || type == NETCONFA_IGNORE_ROUTES_WITH_LINKDOWN) && if ((all || type == NETCONFA_IGNORE_ROUTES_WITH_LINKDOWN) &&
nla_put_s32(skb, NETCONFA_IGNORE_ROUTES_WITH_LINKDOWN, nla_put_s32(skb, NETCONFA_IGNORE_ROUTES_WITH_LINKDOWN,
IPV4_DEVCONF(*devconf, IGNORE_ROUTES_WITH_LINKDOWN)) < 0) IPV4_DEVCONF(*devconf, IGNORE_ROUTES_WITH_LINKDOWN)) < 0)
goto nla_put_failure; goto nla_put_failure;
...@@ -1893,14 +1899,14 @@ static int inet_netconf_get_devconf(struct sk_buff *in_skb, ...@@ -1893,14 +1899,14 @@ static int inet_netconf_get_devconf(struct sk_buff *in_skb,
} }
err = -ENOBUFS; err = -ENOBUFS;
skb = nlmsg_new(inet_netconf_msgsize_devconf(-1), GFP_ATOMIC); skb = nlmsg_new(inet_netconf_msgsize_devconf(NETCONFA_ALL), GFP_ATOMIC);
if (!skb) if (!skb)
goto errout; goto errout;
err = inet_netconf_fill_devconf(skb, ifindex, devconf, err = inet_netconf_fill_devconf(skb, ifindex, devconf,
NETLINK_CB(in_skb).portid, NETLINK_CB(in_skb).portid,
nlh->nlmsg_seq, RTM_NEWNETCONF, 0, nlh->nlmsg_seq, RTM_NEWNETCONF, 0,
-1); NETCONFA_ALL);
if (err < 0) { if (err < 0) {
/* -EMSGSIZE implies BUG in inet_netconf_msgsize_devconf() */ /* -EMSGSIZE implies BUG in inet_netconf_msgsize_devconf() */
WARN_ON(err == -EMSGSIZE); WARN_ON(err == -EMSGSIZE);
...@@ -1944,7 +1950,7 @@ static int inet_netconf_dump_devconf(struct sk_buff *skb, ...@@ -1944,7 +1950,7 @@ static int inet_netconf_dump_devconf(struct sk_buff *skb,
cb->nlh->nlmsg_seq, cb->nlh->nlmsg_seq,
RTM_NEWNETCONF, RTM_NEWNETCONF,
NLM_F_MULTI, NLM_F_MULTI,
-1) < 0) { NETCONFA_ALL) < 0) {
rcu_read_unlock(); rcu_read_unlock();
goto done; goto done;
} }
...@@ -1960,7 +1966,7 @@ static int inet_netconf_dump_devconf(struct sk_buff *skb, ...@@ -1960,7 +1966,7 @@ static int inet_netconf_dump_devconf(struct sk_buff *skb,
NETLINK_CB(cb->skb).portid, NETLINK_CB(cb->skb).portid,
cb->nlh->nlmsg_seq, cb->nlh->nlmsg_seq,
RTM_NEWNETCONF, NLM_F_MULTI, RTM_NEWNETCONF, NLM_F_MULTI,
-1) < 0) NETCONFA_ALL) < 0)
goto done; goto done;
else else
h++; h++;
...@@ -1971,7 +1977,7 @@ static int inet_netconf_dump_devconf(struct sk_buff *skb, ...@@ -1971,7 +1977,7 @@ static int inet_netconf_dump_devconf(struct sk_buff *skb,
NETLINK_CB(cb->skb).portid, NETLINK_CB(cb->skb).portid,
cb->nlh->nlmsg_seq, cb->nlh->nlmsg_seq,
RTM_NEWNETCONF, NLM_F_MULTI, RTM_NEWNETCONF, NLM_F_MULTI,
-1) < 0) NETCONFA_ALL) < 0)
goto done; goto done;
else else
h++; h++;
......
...@@ -473,18 +473,21 @@ static int inet6_netconf_msgsize_devconf(int type) ...@@ -473,18 +473,21 @@ static int inet6_netconf_msgsize_devconf(int type)
{ {
int size = NLMSG_ALIGN(sizeof(struct netconfmsg)) int size = NLMSG_ALIGN(sizeof(struct netconfmsg))
+ nla_total_size(4); /* NETCONFA_IFINDEX */ + nla_total_size(4); /* NETCONFA_IFINDEX */
bool all = false;
/* type -1 is used for ALL */ if (type == NETCONFA_ALL)
if (type == -1 || type == NETCONFA_FORWARDING) all = true;
if (all || type == NETCONFA_FORWARDING)
size += nla_total_size(4); size += nla_total_size(4);
#ifdef CONFIG_IPV6_MROUTE #ifdef CONFIG_IPV6_MROUTE
if (type == -1 || type == NETCONFA_MC_FORWARDING) if (all || type == NETCONFA_MC_FORWARDING)
size += nla_total_size(4); size += nla_total_size(4);
#endif #endif
if (type == -1 || type == NETCONFA_PROXY_NEIGH) if (all || type == NETCONFA_PROXY_NEIGH)
size += nla_total_size(4); size += nla_total_size(4);
if (type == -1 || type == NETCONFA_IGNORE_ROUTES_WITH_LINKDOWN) if (all || type == NETCONFA_IGNORE_ROUTES_WITH_LINKDOWN)
size += nla_total_size(4); size += nla_total_size(4);
return size; return size;
...@@ -497,33 +500,36 @@ static int inet6_netconf_fill_devconf(struct sk_buff *skb, int ifindex, ...@@ -497,33 +500,36 @@ static int inet6_netconf_fill_devconf(struct sk_buff *skb, int ifindex,
{ {
struct nlmsghdr *nlh; struct nlmsghdr *nlh;
struct netconfmsg *ncm; struct netconfmsg *ncm;
bool all = false;
nlh = nlmsg_put(skb, portid, seq, event, sizeof(struct netconfmsg), nlh = nlmsg_put(skb, portid, seq, event, sizeof(struct netconfmsg),
flags); flags);
if (!nlh) if (!nlh)
return -EMSGSIZE; return -EMSGSIZE;
if (type == NETCONFA_ALL)
all = true;
ncm = nlmsg_data(nlh); ncm = nlmsg_data(nlh);
ncm->ncm_family = AF_INET6; ncm->ncm_family = AF_INET6;
if (nla_put_s32(skb, NETCONFA_IFINDEX, ifindex) < 0) if (nla_put_s32(skb, NETCONFA_IFINDEX, ifindex) < 0)
goto nla_put_failure; goto nla_put_failure;
/* type -1 is used for ALL */ if ((all || type == NETCONFA_FORWARDING) &&
if ((type == -1 || type == NETCONFA_FORWARDING) &&
nla_put_s32(skb, NETCONFA_FORWARDING, devconf->forwarding) < 0) nla_put_s32(skb, NETCONFA_FORWARDING, devconf->forwarding) < 0)
goto nla_put_failure; goto nla_put_failure;
#ifdef CONFIG_IPV6_MROUTE #ifdef CONFIG_IPV6_MROUTE
if ((type == -1 || type == NETCONFA_MC_FORWARDING) && if ((all || type == NETCONFA_MC_FORWARDING) &&
nla_put_s32(skb, NETCONFA_MC_FORWARDING, nla_put_s32(skb, NETCONFA_MC_FORWARDING,
devconf->mc_forwarding) < 0) devconf->mc_forwarding) < 0)
goto nla_put_failure; goto nla_put_failure;
#endif #endif
if ((type == -1 || type == NETCONFA_PROXY_NEIGH) && if ((all || type == NETCONFA_PROXY_NEIGH) &&
nla_put_s32(skb, NETCONFA_PROXY_NEIGH, devconf->proxy_ndp) < 0) nla_put_s32(skb, NETCONFA_PROXY_NEIGH, devconf->proxy_ndp) < 0)
goto nla_put_failure; goto nla_put_failure;
if ((type == -1 || type == NETCONFA_IGNORE_ROUTES_WITH_LINKDOWN) && if ((all || type == NETCONFA_IGNORE_ROUTES_WITH_LINKDOWN) &&
nla_put_s32(skb, NETCONFA_IGNORE_ROUTES_WITH_LINKDOWN, nla_put_s32(skb, NETCONFA_IGNORE_ROUTES_WITH_LINKDOWN,
devconf->ignore_routes_with_linkdown) < 0) devconf->ignore_routes_with_linkdown) < 0)
goto nla_put_failure; goto nla_put_failure;
...@@ -609,14 +615,14 @@ static int inet6_netconf_get_devconf(struct sk_buff *in_skb, ...@@ -609,14 +615,14 @@ static int inet6_netconf_get_devconf(struct sk_buff *in_skb,
} }
err = -ENOBUFS; err = -ENOBUFS;
skb = nlmsg_new(inet6_netconf_msgsize_devconf(-1), GFP_ATOMIC); skb = nlmsg_new(inet6_netconf_msgsize_devconf(NETCONFA_ALL), GFP_ATOMIC);
if (!skb) if (!skb)
goto errout; goto errout;
err = inet6_netconf_fill_devconf(skb, ifindex, devconf, err = inet6_netconf_fill_devconf(skb, ifindex, devconf,
NETLINK_CB(in_skb).portid, NETLINK_CB(in_skb).portid,
nlh->nlmsg_seq, RTM_NEWNETCONF, 0, nlh->nlmsg_seq, RTM_NEWNETCONF, 0,
-1); NETCONFA_ALL);
if (err < 0) { if (err < 0) {
/* -EMSGSIZE implies BUG in inet6_netconf_msgsize_devconf() */ /* -EMSGSIZE implies BUG in inet6_netconf_msgsize_devconf() */
WARN_ON(err == -EMSGSIZE); WARN_ON(err == -EMSGSIZE);
...@@ -660,7 +666,7 @@ static int inet6_netconf_dump_devconf(struct sk_buff *skb, ...@@ -660,7 +666,7 @@ static int inet6_netconf_dump_devconf(struct sk_buff *skb,
cb->nlh->nlmsg_seq, cb->nlh->nlmsg_seq,
RTM_NEWNETCONF, RTM_NEWNETCONF,
NLM_F_MULTI, NLM_F_MULTI,
-1) < 0) { NETCONFA_ALL) < 0) {
rcu_read_unlock(); rcu_read_unlock();
goto done; goto done;
} }
...@@ -676,7 +682,7 @@ static int inet6_netconf_dump_devconf(struct sk_buff *skb, ...@@ -676,7 +682,7 @@ static int inet6_netconf_dump_devconf(struct sk_buff *skb,
NETLINK_CB(cb->skb).portid, NETLINK_CB(cb->skb).portid,
cb->nlh->nlmsg_seq, cb->nlh->nlmsg_seq,
RTM_NEWNETCONF, NLM_F_MULTI, RTM_NEWNETCONF, NLM_F_MULTI,
-1) < 0) NETCONFA_ALL) < 0)
goto done; goto done;
else else
h++; h++;
...@@ -687,7 +693,7 @@ static int inet6_netconf_dump_devconf(struct sk_buff *skb, ...@@ -687,7 +693,7 @@ static int inet6_netconf_dump_devconf(struct sk_buff *skb,
NETLINK_CB(cb->skb).portid, NETLINK_CB(cb->skb).portid,
cb->nlh->nlmsg_seq, cb->nlh->nlmsg_seq,
RTM_NEWNETCONF, NLM_F_MULTI, RTM_NEWNETCONF, NLM_F_MULTI,
-1) < 0) NETCONFA_ALL) < 0)
goto done; goto done;
else else
h++; h++;
......
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