Skip to content

Commit 136ba62

Browse files
Zhang Shengjudavem330
authored andcommitted
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: Zhang Shengju <zhangshengju@cmss.chinamobile.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 39d2ade commit 136ba62

File tree

3 files changed

+45
-32
lines changed

3 files changed

+45
-32
lines changed

include/uapi/linux/netconf.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ enum {
1919
__NETCONFA_MAX
2020
};
2121
#define NETCONFA_MAX (__NETCONFA_MAX - 1)
22+
#define NETCONFA_ALL -1
2223

2324
#define NETCONFA_IFINDEX_ALL -1
2425
#define NETCONFA_IFINDEX_DEFAULT -2

net/ipv4/devinet.c

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1753,17 +1753,20 @@ static int inet_netconf_msgsize_devconf(int type)
17531753
{
17541754
int size = NLMSG_ALIGN(sizeof(struct netconfmsg))
17551755
+ nla_total_size(4); /* NETCONFA_IFINDEX */
1756+
bool all = false;
17561757

1757-
/* type -1 is used for ALL */
1758-
if (type == -1 || type == NETCONFA_FORWARDING)
1758+
if (type == NETCONFA_ALL)
1759+
all = true;
1760+
1761+
if (all || type == NETCONFA_FORWARDING)
17591762
size += nla_total_size(4);
1760-
if (type == -1 || type == NETCONFA_RP_FILTER)
1763+
if (all || type == NETCONFA_RP_FILTER)
17611764
size += nla_total_size(4);
1762-
if (type == -1 || type == NETCONFA_MC_FORWARDING)
1765+
if (all || type == NETCONFA_MC_FORWARDING)
17631766
size += nla_total_size(4);
1764-
if (type == -1 || type == NETCONFA_PROXY_NEIGH)
1767+
if (all || type == NETCONFA_PROXY_NEIGH)
17651768
size += nla_total_size(4);
1766-
if (type == -1 || type == NETCONFA_IGNORE_ROUTES_WITH_LINKDOWN)
1769+
if (all || type == NETCONFA_IGNORE_ROUTES_WITH_LINKDOWN)
17671770
size += nla_total_size(4);
17681771

17691772
return size;
@@ -1776,36 +1779,39 @@ static int inet_netconf_fill_devconf(struct sk_buff *skb, int ifindex,
17761779
{
17771780
struct nlmsghdr *nlh;
17781781
struct netconfmsg *ncm;
1782+
bool all = false;
17791783

17801784
nlh = nlmsg_put(skb, portid, seq, event, sizeof(struct netconfmsg),
17811785
flags);
17821786
if (!nlh)
17831787
return -EMSGSIZE;
17841788

1789+
if (type == NETCONFA_ALL)
1790+
all = true;
1791+
17851792
ncm = nlmsg_data(nlh);
17861793
ncm->ncm_family = AF_INET;
17871794

17881795
if (nla_put_s32(skb, NETCONFA_IFINDEX, ifindex) < 0)
17891796
goto nla_put_failure;
17901797

1791-
/* type -1 is used for ALL */
1792-
if ((type == -1 || type == NETCONFA_FORWARDING) &&
1798+
if ((all || type == NETCONFA_FORWARDING) &&
17931799
nla_put_s32(skb, NETCONFA_FORWARDING,
17941800
IPV4_DEVCONF(*devconf, FORWARDING)) < 0)
17951801
goto nla_put_failure;
1796-
if ((type == -1 || type == NETCONFA_RP_FILTER) &&
1802+
if ((all || type == NETCONFA_RP_FILTER) &&
17971803
nla_put_s32(skb, NETCONFA_RP_FILTER,
17981804
IPV4_DEVCONF(*devconf, RP_FILTER)) < 0)
17991805
goto nla_put_failure;
1800-
if ((type == -1 || type == NETCONFA_MC_FORWARDING) &&
1806+
if ((all || type == NETCONFA_MC_FORWARDING) &&
18011807
nla_put_s32(skb, NETCONFA_MC_FORWARDING,
18021808
IPV4_DEVCONF(*devconf, MC_FORWARDING)) < 0)
18031809
goto nla_put_failure;
1804-
if ((type == -1 || type == NETCONFA_PROXY_NEIGH) &&
1810+
if ((all || type == NETCONFA_PROXY_NEIGH) &&
18051811
nla_put_s32(skb, NETCONFA_PROXY_NEIGH,
18061812
IPV4_DEVCONF(*devconf, PROXY_ARP)) < 0)
18071813
goto nla_put_failure;
1808-
if ((type == -1 || type == NETCONFA_IGNORE_ROUTES_WITH_LINKDOWN) &&
1814+
if ((all || type == NETCONFA_IGNORE_ROUTES_WITH_LINKDOWN) &&
18091815
nla_put_s32(skb, NETCONFA_IGNORE_ROUTES_WITH_LINKDOWN,
18101816
IPV4_DEVCONF(*devconf, IGNORE_ROUTES_WITH_LINKDOWN)) < 0)
18111817
goto nla_put_failure;
@@ -1893,14 +1899,14 @@ static int inet_netconf_get_devconf(struct sk_buff *in_skb,
18931899
}
18941900

18951901
err = -ENOBUFS;
1896-
skb = nlmsg_new(inet_netconf_msgsize_devconf(-1), GFP_ATOMIC);
1902+
skb = nlmsg_new(inet_netconf_msgsize_devconf(NETCONFA_ALL), GFP_ATOMIC);
18971903
if (!skb)
18981904
goto errout;
18991905

19001906
err = inet_netconf_fill_devconf(skb, ifindex, devconf,
19011907
NETLINK_CB(in_skb).portid,
19021908
nlh->nlmsg_seq, RTM_NEWNETCONF, 0,
1903-
-1);
1909+
NETCONFA_ALL);
19041910
if (err < 0) {
19051911
/* -EMSGSIZE implies BUG in inet_netconf_msgsize_devconf() */
19061912
WARN_ON(err == -EMSGSIZE);
@@ -1944,7 +1950,7 @@ static int inet_netconf_dump_devconf(struct sk_buff *skb,
19441950
cb->nlh->nlmsg_seq,
19451951
RTM_NEWNETCONF,
19461952
NLM_F_MULTI,
1947-
-1) < 0) {
1953+
NETCONFA_ALL) < 0) {
19481954
rcu_read_unlock();
19491955
goto done;
19501956
}
@@ -1960,7 +1966,7 @@ static int inet_netconf_dump_devconf(struct sk_buff *skb,
19601966
NETLINK_CB(cb->skb).portid,
19611967
cb->nlh->nlmsg_seq,
19621968
RTM_NEWNETCONF, NLM_F_MULTI,
1963-
-1) < 0)
1969+
NETCONFA_ALL) < 0)
19641970
goto done;
19651971
else
19661972
h++;
@@ -1971,7 +1977,7 @@ static int inet_netconf_dump_devconf(struct sk_buff *skb,
19711977
NETLINK_CB(cb->skb).portid,
19721978
cb->nlh->nlmsg_seq,
19731979
RTM_NEWNETCONF, NLM_F_MULTI,
1974-
-1) < 0)
1980+
NETCONFA_ALL) < 0)
19751981
goto done;
19761982
else
19771983
h++;

net/ipv6/addrconf.c

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -473,18 +473,21 @@ static int inet6_netconf_msgsize_devconf(int type)
473473
{
474474
int size = NLMSG_ALIGN(sizeof(struct netconfmsg))
475475
+ nla_total_size(4); /* NETCONFA_IFINDEX */
476+
bool all = false;
476477

477-
/* type -1 is used for ALL */
478-
if (type == -1 || type == NETCONFA_FORWARDING)
478+
if (type == NETCONFA_ALL)
479+
all = true;
480+
481+
if (all || type == NETCONFA_FORWARDING)
479482
size += nla_total_size(4);
480483
#ifdef CONFIG_IPV6_MROUTE
481-
if (type == -1 || type == NETCONFA_MC_FORWARDING)
484+
if (all || type == NETCONFA_MC_FORWARDING)
482485
size += nla_total_size(4);
483486
#endif
484-
if (type == -1 || type == NETCONFA_PROXY_NEIGH)
487+
if (all || type == NETCONFA_PROXY_NEIGH)
485488
size += nla_total_size(4);
486489

487-
if (type == -1 || type == NETCONFA_IGNORE_ROUTES_WITH_LINKDOWN)
490+
if (all || type == NETCONFA_IGNORE_ROUTES_WITH_LINKDOWN)
488491
size += nla_total_size(4);
489492

490493
return size;
@@ -497,33 +500,36 @@ static int inet6_netconf_fill_devconf(struct sk_buff *skb, int ifindex,
497500
{
498501
struct nlmsghdr *nlh;
499502
struct netconfmsg *ncm;
503+
bool all = false;
500504

501505
nlh = nlmsg_put(skb, portid, seq, event, sizeof(struct netconfmsg),
502506
flags);
503507
if (!nlh)
504508
return -EMSGSIZE;
505509

510+
if (type == NETCONFA_ALL)
511+
all = true;
512+
506513
ncm = nlmsg_data(nlh);
507514
ncm->ncm_family = AF_INET6;
508515

509516
if (nla_put_s32(skb, NETCONFA_IFINDEX, ifindex) < 0)
510517
goto nla_put_failure;
511518

512-
/* type -1 is used for ALL */
513-
if ((type == -1 || type == NETCONFA_FORWARDING) &&
519+
if ((all || type == NETCONFA_FORWARDING) &&
514520
nla_put_s32(skb, NETCONFA_FORWARDING, devconf->forwarding) < 0)
515521
goto nla_put_failure;
516522
#ifdef CONFIG_IPV6_MROUTE
517-
if ((type == -1 || type == NETCONFA_MC_FORWARDING) &&
523+
if ((all || type == NETCONFA_MC_FORWARDING) &&
518524
nla_put_s32(skb, NETCONFA_MC_FORWARDING,
519525
devconf->mc_forwarding) < 0)
520526
goto nla_put_failure;
521527
#endif
522-
if ((type == -1 || type == NETCONFA_PROXY_NEIGH) &&
528+
if ((all || type == NETCONFA_PROXY_NEIGH) &&
523529
nla_put_s32(skb, NETCONFA_PROXY_NEIGH, devconf->proxy_ndp) < 0)
524530
goto nla_put_failure;
525531

526-
if ((type == -1 || type == NETCONFA_IGNORE_ROUTES_WITH_LINKDOWN) &&
532+
if ((all || type == NETCONFA_IGNORE_ROUTES_WITH_LINKDOWN) &&
527533
nla_put_s32(skb, NETCONFA_IGNORE_ROUTES_WITH_LINKDOWN,
528534
devconf->ignore_routes_with_linkdown) < 0)
529535
goto nla_put_failure;
@@ -609,14 +615,14 @@ static int inet6_netconf_get_devconf(struct sk_buff *in_skb,
609615
}
610616

611617
err = -ENOBUFS;
612-
skb = nlmsg_new(inet6_netconf_msgsize_devconf(-1), GFP_ATOMIC);
618+
skb = nlmsg_new(inet6_netconf_msgsize_devconf(NETCONFA_ALL), GFP_ATOMIC);
613619
if (!skb)
614620
goto errout;
615621

616622
err = inet6_netconf_fill_devconf(skb, ifindex, devconf,
617623
NETLINK_CB(in_skb).portid,
618624
nlh->nlmsg_seq, RTM_NEWNETCONF, 0,
619-
-1);
625+
NETCONFA_ALL);
620626
if (err < 0) {
621627
/* -EMSGSIZE implies BUG in inet6_netconf_msgsize_devconf() */
622628
WARN_ON(err == -EMSGSIZE);
@@ -660,7 +666,7 @@ static int inet6_netconf_dump_devconf(struct sk_buff *skb,
660666
cb->nlh->nlmsg_seq,
661667
RTM_NEWNETCONF,
662668
NLM_F_MULTI,
663-
-1) < 0) {
669+
NETCONFA_ALL) < 0) {
664670
rcu_read_unlock();
665671
goto done;
666672
}
@@ -676,7 +682,7 @@ static int inet6_netconf_dump_devconf(struct sk_buff *skb,
676682
NETLINK_CB(cb->skb).portid,
677683
cb->nlh->nlmsg_seq,
678684
RTM_NEWNETCONF, NLM_F_MULTI,
679-
-1) < 0)
685+
NETCONFA_ALL) < 0)
680686
goto done;
681687
else
682688
h++;
@@ -687,7 +693,7 @@ static int inet6_netconf_dump_devconf(struct sk_buff *skb,
687693
NETLINK_CB(cb->skb).portid,
688694
cb->nlh->nlmsg_seq,
689695
RTM_NEWNETCONF, NLM_F_MULTI,
690-
-1) < 0)
696+
NETCONFA_ALL) < 0)
691697
goto done;
692698
else
693699
h++;

0 commit comments

Comments
 (0)