Skip to content

Commit 7a35a50

Browse files
dsaherndavem330
authored andcommitted
neighbor: Add extack messages for add and delete commands
Add extack messages for failures in neigh_add and neigh_delete. Signed-off-by: David Ahern <dsahern@gmail.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent f5d6c3e commit 7a35a50

File tree

1 file changed

+39
-16
lines changed

1 file changed

+39
-16
lines changed

net/core/neighbour.c

Lines changed: 39 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1137,8 +1137,9 @@ static void neigh_update_hhs(struct neighbour *neigh)
11371137
Caller MUST hold reference count on the entry.
11381138
*/
11391139

1140-
int neigh_update(struct neighbour *neigh, const u8 *lladdr, u8 new,
1141-
u32 flags, u32 nlmsg_pid)
1140+
static int __neigh_update(struct neighbour *neigh, const u8 *lladdr,
1141+
u8 new, u32 flags, u32 nlmsg_pid,
1142+
struct netlink_ext_ack *extack)
11421143
{
11431144
u8 old;
11441145
int err;
@@ -1155,8 +1156,10 @@ int neigh_update(struct neighbour *neigh, const u8 *lladdr, u8 new,
11551156
if (!(flags & NEIGH_UPDATE_F_ADMIN) &&
11561157
(old & (NUD_NOARP | NUD_PERMANENT)))
11571158
goto out;
1158-
if (neigh->dead)
1159+
if (neigh->dead) {
1160+
NL_SET_ERR_MSG(extack, "Neighbor entry is now dead");
11591161
goto out;
1162+
}
11601163

11611164
neigh_update_ext_learned(neigh, flags, &notify);
11621165

@@ -1193,8 +1196,10 @@ int neigh_update(struct neighbour *neigh, const u8 *lladdr, u8 new,
11931196
use it, otherwise discard the request.
11941197
*/
11951198
err = -EINVAL;
1196-
if (!(old & NUD_VALID))
1199+
if (!(old & NUD_VALID)) {
1200+
NL_SET_ERR_MSG(extack, "No link layer address given");
11971201
goto out;
1202+
}
11981203
lladdr = neigh->ha;
11991204
}
12001205

@@ -1307,6 +1312,12 @@ int neigh_update(struct neighbour *neigh, const u8 *lladdr, u8 new,
13071312

13081313
return err;
13091314
}
1315+
1316+
int neigh_update(struct neighbour *neigh, const u8 *lladdr, u8 new,
1317+
u32 flags, u32 nlmsg_pid)
1318+
{
1319+
return __neigh_update(neigh, lladdr, new, flags, nlmsg_pid, NULL);
1320+
}
13101321
EXPORT_SYMBOL(neigh_update);
13111322

13121323
/* Update the neigh to listen temporarily for probe responses, even if it is
@@ -1678,8 +1689,10 @@ static int neigh_delete(struct sk_buff *skb, struct nlmsghdr *nlh,
16781689
goto out;
16791690

16801691
dst_attr = nlmsg_find_attr(nlh, sizeof(*ndm), NDA_DST);
1681-
if (dst_attr == NULL)
1692+
if (!dst_attr) {
1693+
NL_SET_ERR_MSG(extack, "Network address not specified");
16821694
goto out;
1695+
}
16831696

16841697
ndm = nlmsg_data(nlh);
16851698
if (ndm->ndm_ifindex) {
@@ -1694,8 +1707,10 @@ static int neigh_delete(struct sk_buff *skb, struct nlmsghdr *nlh,
16941707
if (tbl == NULL)
16951708
return -EAFNOSUPPORT;
16961709

1697-
if (nla_len(dst_attr) < (int)tbl->key_len)
1710+
if (nla_len(dst_attr) < (int)tbl->key_len) {
1711+
NL_SET_ERR_MSG(extack, "Invalid network address");
16981712
goto out;
1713+
}
16991714

17001715
if (ndm->ndm_flags & NTF_PROXY) {
17011716
err = pneigh_delete(tbl, net, nla_data(dst_attr), dev);
@@ -1711,10 +1726,9 @@ static int neigh_delete(struct sk_buff *skb, struct nlmsghdr *nlh,
17111726
goto out;
17121727
}
17131728

1714-
err = neigh_update(neigh, NULL, NUD_FAILED,
1715-
NEIGH_UPDATE_F_OVERRIDE |
1716-
NEIGH_UPDATE_F_ADMIN,
1717-
NETLINK_CB(skb).portid);
1729+
err = __neigh_update(neigh, NULL, NUD_FAILED,
1730+
NEIGH_UPDATE_F_OVERRIDE | NEIGH_UPDATE_F_ADMIN,
1731+
NETLINK_CB(skb).portid, extack);
17181732
write_lock_bh(&tbl->lock);
17191733
neigh_release(neigh);
17201734
neigh_remove_one(neigh, tbl);
@@ -1744,8 +1758,10 @@ static int neigh_add(struct sk_buff *skb, struct nlmsghdr *nlh,
17441758
goto out;
17451759

17461760
err = -EINVAL;
1747-
if (tb[NDA_DST] == NULL)
1761+
if (!tb[NDA_DST]) {
1762+
NL_SET_ERR_MSG(extack, "Network address not specified");
17481763
goto out;
1764+
}
17491765

17501766
ndm = nlmsg_data(nlh);
17511767
if (ndm->ndm_ifindex) {
@@ -1755,16 +1771,21 @@ static int neigh_add(struct sk_buff *skb, struct nlmsghdr *nlh,
17551771
goto out;
17561772
}
17571773

1758-
if (tb[NDA_LLADDR] && nla_len(tb[NDA_LLADDR]) < dev->addr_len)
1774+
if (tb[NDA_LLADDR] && nla_len(tb[NDA_LLADDR]) < dev->addr_len) {
1775+
NL_SET_ERR_MSG(extack, "Invalid link address");
17591776
goto out;
1777+
}
17601778
}
17611779

17621780
tbl = neigh_find_table(ndm->ndm_family);
17631781
if (tbl == NULL)
17641782
return -EAFNOSUPPORT;
17651783

1766-
if (nla_len(tb[NDA_DST]) < (int)tbl->key_len)
1784+
if (nla_len(tb[NDA_DST]) < (int)tbl->key_len) {
1785+
NL_SET_ERR_MSG(extack, "Invalid network address");
17671786
goto out;
1787+
}
1788+
17681789
dst = nla_data(tb[NDA_DST]);
17691790
lladdr = tb[NDA_LLADDR] ? nla_data(tb[NDA_LLADDR]) : NULL;
17701791

@@ -1780,8 +1801,10 @@ static int neigh_add(struct sk_buff *skb, struct nlmsghdr *nlh,
17801801
goto out;
17811802
}
17821803

1783-
if (dev == NULL)
1804+
if (!dev) {
1805+
NL_SET_ERR_MSG(extack, "Device not specified");
17841806
goto out;
1807+
}
17851808

17861809
neigh = neigh_lookup(tbl, dst, dev);
17871810
if (neigh == NULL) {
@@ -1817,8 +1840,8 @@ static int neigh_add(struct sk_buff *skb, struct nlmsghdr *nlh,
18171840
neigh_event_send(neigh, NULL);
18181841
err = 0;
18191842
} else
1820-
err = neigh_update(neigh, lladdr, ndm->ndm_state, flags,
1821-
NETLINK_CB(skb).portid);
1843+
err = __neigh_update(neigh, lladdr, ndm->ndm_state, flags,
1844+
NETLINK_CB(skb).portid, extack);
18221845
neigh_release(neigh);
18231846

18241847
out:

0 commit comments

Comments
 (0)