Skip to content

Commit 6ecc4fd

Browse files
T-Xsimonwunderlich
authored andcommitted
batman-adv: netlink: reduce duplicate code by returning interfaces
Reduce duplicate code by using netlink helpers which return the soft/hard interface directly. Instead of returning an interface index which we are typically not interested in. Signed-off-by: Linus Lüssing <[email protected]> Signed-off-by: Sven Eckelmann <[email protected]> Signed-off-by: Simon Wunderlich <[email protected]>
1 parent 425970f commit 6ecc4fd

File tree

8 files changed

+174
-209
lines changed

8 files changed

+174
-209
lines changed

net/batman-adv/bridge_loop_avoidance.c

Lines changed: 7 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include <linux/compiler.h>
1313
#include <linux/container_of.h>
1414
#include <linux/crc16.h>
15+
#include <linux/err.h>
1516
#include <linux/errno.h>
1617
#include <linux/etherdevice.h>
1718
#include <linux/gfp.h>
@@ -38,7 +39,6 @@
3839
#include <net/arp.h>
3940
#include <net/genetlink.h>
4041
#include <net/netlink.h>
41-
#include <net/sock.h>
4242
#include <uapi/linux/batadv_packet.h>
4343
#include <uapi/linux/batman_adv.h>
4444

@@ -47,7 +47,6 @@
4747
#include "log.h"
4848
#include "netlink.h"
4949
#include "originator.h"
50-
#include "soft-interface.h"
5150
#include "translation-table.h"
5251

5352
static const u8 batadv_announce_mac[4] = {0x43, 0x05, 0x43, 0x05};
@@ -2233,25 +2232,16 @@ int batadv_bla_claim_dump(struct sk_buff *msg, struct netlink_callback *cb)
22332232
{
22342233
struct batadv_hard_iface *primary_if = NULL;
22352234
int portid = NETLINK_CB(cb->skb).portid;
2236-
struct net *net = sock_net(cb->skb->sk);
22372235
struct net_device *soft_iface;
22382236
struct batadv_hashtable *hash;
22392237
struct batadv_priv *bat_priv;
22402238
int bucket = cb->args[0];
22412239
int idx = cb->args[1];
2242-
int ifindex;
22432240
int ret = 0;
22442241

2245-
ifindex = batadv_netlink_get_ifindex(cb->nlh,
2246-
BATADV_ATTR_MESH_IFINDEX);
2247-
if (!ifindex)
2248-
return -EINVAL;
2249-
2250-
soft_iface = dev_get_by_index(net, ifindex);
2251-
if (!soft_iface || !batadv_softif_is_valid(soft_iface)) {
2252-
ret = -ENODEV;
2253-
goto out;
2254-
}
2242+
soft_iface = batadv_netlink_get_softif(cb);
2243+
if (IS_ERR(soft_iface))
2244+
return PTR_ERR(soft_iface);
22552245

22562246
bat_priv = netdev_priv(soft_iface);
22572247
hash = bat_priv->bla.claim_hash;
@@ -2403,25 +2393,16 @@ int batadv_bla_backbone_dump(struct sk_buff *msg, struct netlink_callback *cb)
24032393
{
24042394
struct batadv_hard_iface *primary_if = NULL;
24052395
int portid = NETLINK_CB(cb->skb).portid;
2406-
struct net *net = sock_net(cb->skb->sk);
24072396
struct net_device *soft_iface;
24082397
struct batadv_hashtable *hash;
24092398
struct batadv_priv *bat_priv;
24102399
int bucket = cb->args[0];
24112400
int idx = cb->args[1];
2412-
int ifindex;
24132401
int ret = 0;
24142402

2415-
ifindex = batadv_netlink_get_ifindex(cb->nlh,
2416-
BATADV_ATTR_MESH_IFINDEX);
2417-
if (!ifindex)
2418-
return -EINVAL;
2419-
2420-
soft_iface = dev_get_by_index(net, ifindex);
2421-
if (!soft_iface || !batadv_softif_is_valid(soft_iface)) {
2422-
ret = -ENODEV;
2423-
goto out;
2424-
}
2403+
soft_iface = batadv_netlink_get_softif(cb);
2404+
if (IS_ERR(soft_iface))
2405+
return PTR_ERR(soft_iface);
24252406

24262407
bat_priv = netdev_priv(soft_iface);
24272408
hash = bat_priv->bla.backbone_hash;

net/batman-adv/distributed-arp-table.c

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include <linux/bitops.h>
1212
#include <linux/byteorder/generic.h>
1313
#include <linux/container_of.h>
14+
#include <linux/err.h>
1415
#include <linux/errno.h>
1516
#include <linux/etherdevice.h>
1617
#include <linux/gfp.h>
@@ -36,7 +37,6 @@
3637
#include <net/arp.h>
3738
#include <net/genetlink.h>
3839
#include <net/netlink.h>
39-
#include <net/sock.h>
4040
#include <uapi/linux/batman_adv.h>
4141

4242
#include "bridge_loop_avoidance.h"
@@ -46,7 +46,6 @@
4646
#include "netlink.h"
4747
#include "originator.h"
4848
#include "send.h"
49-
#include "soft-interface.h"
5049
#include "translation-table.h"
5150
#include "tvlv.h"
5251

@@ -937,25 +936,16 @@ int batadv_dat_cache_dump(struct sk_buff *msg, struct netlink_callback *cb)
937936
{
938937
struct batadv_hard_iface *primary_if = NULL;
939938
int portid = NETLINK_CB(cb->skb).portid;
940-
struct net *net = sock_net(cb->skb->sk);
941939
struct net_device *soft_iface;
942940
struct batadv_hashtable *hash;
943941
struct batadv_priv *bat_priv;
944942
int bucket = cb->args[0];
945943
int idx = cb->args[1];
946-
int ifindex;
947944
int ret = 0;
948945

949-
ifindex = batadv_netlink_get_ifindex(cb->nlh,
950-
BATADV_ATTR_MESH_IFINDEX);
951-
if (!ifindex)
952-
return -EINVAL;
953-
954-
soft_iface = dev_get_by_index(net, ifindex);
955-
if (!soft_iface || !batadv_softif_is_valid(soft_iface)) {
956-
ret = -ENODEV;
957-
goto out;
958-
}
946+
soft_iface = batadv_netlink_get_softif(cb);
947+
if (IS_ERR(soft_iface))
948+
return PTR_ERR(soft_iface);
959949

960950
bat_priv = netdev_priv(soft_iface);
961951
hash = bat_priv->dat.hash;

net/batman-adv/gateway_client.c

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include <linux/atomic.h>
1111
#include <linux/byteorder/generic.h>
1212
#include <linux/container_of.h>
13+
#include <linux/err.h>
1314
#include <linux/errno.h>
1415
#include <linux/etherdevice.h>
1516
#include <linux/gfp.h>
@@ -31,7 +32,6 @@
3132
#include <linux/sprintf.h>
3233
#include <linux/stddef.h>
3334
#include <linux/udp.h>
34-
#include <net/sock.h>
3535
#include <uapi/linux/batadv_packet.h>
3636
#include <uapi/linux/batman_adv.h>
3737

@@ -40,7 +40,6 @@
4040
#include "netlink.h"
4141
#include "originator.h"
4242
#include "routing.h"
43-
#include "soft-interface.h"
4443
#include "translation-table.h"
4544

4645
/* These are the offsets of the "hw type" and "hw address length" in the dhcp
@@ -502,22 +501,13 @@ void batadv_gw_node_free(struct batadv_priv *bat_priv)
502501
int batadv_gw_dump(struct sk_buff *msg, struct netlink_callback *cb)
503502
{
504503
struct batadv_hard_iface *primary_if = NULL;
505-
struct net *net = sock_net(cb->skb->sk);
506504
struct net_device *soft_iface;
507505
struct batadv_priv *bat_priv;
508-
int ifindex;
509506
int ret;
510507

511-
ifindex = batadv_netlink_get_ifindex(cb->nlh,
512-
BATADV_ATTR_MESH_IFINDEX);
513-
if (!ifindex)
514-
return -EINVAL;
515-
516-
soft_iface = dev_get_by_index(net, ifindex);
517-
if (!soft_iface || !batadv_softif_is_valid(soft_iface)) {
518-
ret = -ENODEV;
519-
goto out;
520-
}
508+
soft_iface = batadv_netlink_get_softif(cb);
509+
if (IS_ERR(soft_iface))
510+
return PTR_ERR(soft_iface);
521511

522512
bat_priv = netdev_priv(soft_iface);
523513

net/batman-adv/multicast.c

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include <linux/bug.h>
1313
#include <linux/byteorder/generic.h>
1414
#include <linux/container_of.h>
15+
#include <linux/err.h>
1516
#include <linux/errno.h>
1617
#include <linux/etherdevice.h>
1718
#include <linux/gfp.h>
@@ -46,7 +47,6 @@
4647
#include <net/ip.h>
4748
#include <net/ipv6.h>
4849
#include <net/netlink.h>
49-
#include <net/sock.h>
5050
#include <uapi/linux/batadv_packet.h>
5151
#include <uapi/linux/batman_adv.h>
5252

@@ -56,7 +56,6 @@
5656
#include "log.h"
5757
#include "netlink.h"
5858
#include "send.h"
59-
#include "soft-interface.h"
6059
#include "translation-table.h"
6160
#include "tvlv.h"
6261

@@ -2104,21 +2103,13 @@ batadv_mcast_netlink_get_primary(struct netlink_callback *cb,
21042103
struct batadv_hard_iface **primary_if)
21052104
{
21062105
struct batadv_hard_iface *hard_iface = NULL;
2107-
struct net *net = sock_net(cb->skb->sk);
21082106
struct net_device *soft_iface;
21092107
struct batadv_priv *bat_priv;
2110-
int ifindex;
21112108
int ret = 0;
21122109

2113-
ifindex = batadv_netlink_get_ifindex(cb->nlh, BATADV_ATTR_MESH_IFINDEX);
2114-
if (!ifindex)
2115-
return -EINVAL;
2116-
2117-
soft_iface = dev_get_by_index(net, ifindex);
2118-
if (!soft_iface || !batadv_softif_is_valid(soft_iface)) {
2119-
ret = -ENODEV;
2120-
goto out;
2121-
}
2110+
soft_iface = batadv_netlink_get_softif(cb);
2111+
if (IS_ERR(soft_iface))
2112+
return PTR_ERR(soft_iface);
21222113

21232114
bat_priv = netdev_priv(soft_iface);
21242115

0 commit comments

Comments
 (0)