Skip to content

Commit caf0a75

Browse files
q2venkuba-moo
authored andcommitted
neighbour: Make neigh_valid_get_req() return ndmsg.
neigh_get() passes 4 local variable pointers to neigh_valid_get_req(). If it returns a pointer of struct ndmsg, we do not need to pass two of them. Signed-off-by: Kuniyuki Iwashima <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Jakub Kicinski <[email protected]>
1 parent 7f7f3e1 commit caf0a75

File tree

1 file changed

+19
-24
lines changed

1 file changed

+19
-24
lines changed

net/core/neighbour.c

Lines changed: 19 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2910,10 +2910,9 @@ static int neigh_dump_info(struct sk_buff *skb, struct netlink_callback *cb)
29102910
return err;
29112911
}
29122912

2913-
static int neigh_valid_get_req(const struct nlmsghdr *nlh,
2914-
struct neigh_table **tbl,
2915-
void **dst, int *dev_idx, u8 *ndm_flags,
2916-
struct netlink_ext_ack *extack)
2913+
static struct ndmsg *neigh_valid_get_req(const struct nlmsghdr *nlh,
2914+
struct neigh_table **tbl, void **dst,
2915+
struct netlink_ext_ack *extack)
29172916
{
29182917
struct nlattr *tb[NDA_MAX + 1];
29192918
struct ndmsg *ndm;
@@ -2922,31 +2921,29 @@ static int neigh_valid_get_req(const struct nlmsghdr *nlh,
29222921
ndm = nlmsg_payload(nlh, sizeof(*ndm));
29232922
if (!ndm) {
29242923
NL_SET_ERR_MSG(extack, "Invalid header for neighbor get request");
2925-
return -EINVAL;
2924+
return ERR_PTR(-EINVAL);
29262925
}
29272926

29282927
if (ndm->ndm_pad1 || ndm->ndm_pad2 || ndm->ndm_state ||
29292928
ndm->ndm_type) {
29302929
NL_SET_ERR_MSG(extack, "Invalid values in header for neighbor get request");
2931-
return -EINVAL;
2930+
return ERR_PTR(-EINVAL);
29322931
}
29332932

29342933
if (ndm->ndm_flags & ~NTF_PROXY) {
29352934
NL_SET_ERR_MSG(extack, "Invalid flags in header for neighbor get request");
2936-
return -EINVAL;
2935+
return ERR_PTR(-EINVAL);
29372936
}
29382937

29392938
err = nlmsg_parse_deprecated_strict(nlh, sizeof(struct ndmsg), tb,
29402939
NDA_MAX, nda_policy, extack);
29412940
if (err < 0)
2942-
return err;
2941+
return ERR_PTR(err);
29432942

2944-
*ndm_flags = ndm->ndm_flags;
2945-
*dev_idx = ndm->ndm_ifindex;
29462943
*tbl = neigh_find_table(ndm->ndm_family);
2947-
if (*tbl == NULL) {
2944+
if (!*tbl) {
29482945
NL_SET_ERR_MSG(extack, "Unsupported family in header for neighbor get request");
2949-
return -EAFNOSUPPORT;
2946+
return ERR_PTR(-EAFNOSUPPORT);
29502947
}
29512948

29522949
for (i = 0; i <= NDA_MAX; ++i) {
@@ -2957,17 +2954,17 @@ static int neigh_valid_get_req(const struct nlmsghdr *nlh,
29572954
case NDA_DST:
29582955
if (nla_len(tb[i]) != (int)(*tbl)->key_len) {
29592956
NL_SET_ERR_MSG(extack, "Invalid network address in neighbor get request");
2960-
return -EINVAL;
2957+
return ERR_PTR(-EINVAL);
29612958
}
29622959
*dst = nla_data(tb[i]);
29632960
break;
29642961
default:
29652962
NL_SET_ERR_MSG(extack, "Unsupported attribute in neighbor get request");
2966-
return -EINVAL;
2963+
return ERR_PTR(-EINVAL);
29672964
}
29682965
}
29692966

2970-
return 0;
2967+
return ndm;
29712968
}
29722969

29732970
static inline size_t neigh_nlmsg_size(void)
@@ -3038,18 +3035,16 @@ static int neigh_get(struct sk_buff *in_skb, struct nlmsghdr *nlh,
30383035
struct net_device *dev = NULL;
30393036
struct neigh_table *tbl = NULL;
30403037
struct neighbour *neigh;
3038+
struct ndmsg *ndm;
30413039
void *dst = NULL;
3042-
u8 ndm_flags = 0;
3043-
int dev_idx = 0;
30443040
int err;
30453041

3046-
err = neigh_valid_get_req(nlh, &tbl, &dst, &dev_idx, &ndm_flags,
3047-
extack);
3048-
if (err < 0)
3049-
return err;
3042+
ndm = neigh_valid_get_req(nlh, &tbl, &dst, extack);
3043+
if (IS_ERR(ndm))
3044+
return PTR_ERR(ndm);
30503045

3051-
if (dev_idx) {
3052-
dev = __dev_get_by_index(net, dev_idx);
3046+
if (ndm->ndm_ifindex) {
3047+
dev = __dev_get_by_index(net, ndm->ndm_ifindex);
30533048
if (!dev) {
30543049
NL_SET_ERR_MSG(extack, "Unknown device ifindex");
30553050
return -ENODEV;
@@ -3061,7 +3056,7 @@ static int neigh_get(struct sk_buff *in_skb, struct nlmsghdr *nlh,
30613056
return -EINVAL;
30623057
}
30633058

3064-
if (ndm_flags & NTF_PROXY) {
3059+
if (ndm->ndm_flags & NTF_PROXY) {
30653060
struct pneigh_entry *pn;
30663061

30673062
pn = pneigh_lookup(tbl, net, dst, dev, 0);

0 commit comments

Comments
 (0)