Skip to content

Commit 755f663

Browse files
committed
Merge tag 'batadv-next-for-davem-20180319' of git://git.open-mesh.org/linux-merge
Simon Wunderlich says: ==================== This feature/cleanup patchset includes the following patches: - avoid redundant multicast TT entries, by Linus Luessing - add netlink support for distributed arp table cache and multicast flags, by Linus Luessing (2 patches) ==================== Signed-off-by: David S. Miller <[email protected]>
2 parents bdf5bd7 + 53dd9a6 commit 755f663

File tree

6 files changed

+604
-37
lines changed

6 files changed

+604
-37
lines changed

include/uapi/linux/batman_adv.h

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,53 @@ enum batadv_tt_client_flags {
9191
BATADV_TT_CLIENT_TEMP = (1 << 11),
9292
};
9393

94+
/**
95+
* enum batadv_mcast_flags_priv - Private, own multicast flags
96+
*
97+
* These are internal, multicast related flags. Currently they describe certain
98+
* multicast related attributes of the segment this originator bridges into the
99+
* mesh.
100+
*
101+
* Those attributes are used to determine the public multicast flags this
102+
* originator is going to announce via TT.
103+
*
104+
* For netlink, if BATADV_MCAST_FLAGS_BRIDGED is unset then all querier
105+
* related flags are undefined.
106+
*/
107+
enum batadv_mcast_flags_priv {
108+
/**
109+
* @BATADV_MCAST_FLAGS_BRIDGED: There is a bridge on top of the mesh
110+
* interface.
111+
*/
112+
BATADV_MCAST_FLAGS_BRIDGED = (1 << 0),
113+
114+
/**
115+
* @BATADV_MCAST_FLAGS_QUERIER_IPV4_EXISTS: Whether an IGMP querier
116+
* exists in the mesh
117+
*/
118+
BATADV_MCAST_FLAGS_QUERIER_IPV4_EXISTS = (1 << 1),
119+
120+
/**
121+
* @BATADV_MCAST_FLAGS_QUERIER_IPV6_EXISTS: Whether an MLD querier
122+
* exists in the mesh
123+
*/
124+
BATADV_MCAST_FLAGS_QUERIER_IPV6_EXISTS = (1 << 2),
125+
126+
/**
127+
* @BATADV_MCAST_FLAGS_QUERIER_IPV4_SHADOWING: If an IGMP querier
128+
* exists, whether it is potentially shadowing multicast listeners
129+
* (i.e. querier is behind our own bridge segment)
130+
*/
131+
BATADV_MCAST_FLAGS_QUERIER_IPV4_SHADOWING = (1 << 3),
132+
133+
/**
134+
* @BATADV_MCAST_FLAGS_QUERIER_IPV6_SHADOWING: If an MLD querier
135+
* exists, whether it is potentially shadowing multicast listeners
136+
* (i.e. querier is behind our own bridge segment)
137+
*/
138+
BATADV_MCAST_FLAGS_QUERIER_IPV6_SHADOWING = (1 << 4),
139+
};
140+
94141
/**
95142
* enum batadv_nl_attrs - batman-adv netlink attributes
96143
*/
@@ -272,6 +319,31 @@ enum batadv_nl_attrs {
272319
*/
273320
BATADV_ATTR_BLA_CRC,
274321

322+
/**
323+
* @BATADV_ATTR_DAT_CACHE_IP4ADDRESS: Client IPv4 address
324+
*/
325+
BATADV_ATTR_DAT_CACHE_IP4ADDRESS,
326+
327+
/**
328+
* @BATADV_ATTR_DAT_CACHE_HWADDRESS: Client MAC address
329+
*/
330+
BATADV_ATTR_DAT_CACHE_HWADDRESS,
331+
332+
/**
333+
* @BATADV_ATTR_DAT_CACHE_VID: VLAN ID
334+
*/
335+
BATADV_ATTR_DAT_CACHE_VID,
336+
337+
/**
338+
* @BATADV_ATTR_MCAST_FLAGS: Per originator multicast flags
339+
*/
340+
BATADV_ATTR_MCAST_FLAGS,
341+
342+
/**
343+
* @BATADV_ATTR_MCAST_FLAGS_PRIV: Private, own multicast flags
344+
*/
345+
BATADV_ATTR_MCAST_FLAGS_PRIV,
346+
275347
/* add attributes above here, update the policy in netlink.c */
276348

277349
/**
@@ -361,6 +433,16 @@ enum batadv_nl_commands {
361433
*/
362434
BATADV_CMD_GET_BLA_BACKBONE,
363435

436+
/**
437+
* @BATADV_CMD_GET_DAT_CACHE: Query list of DAT cache entries
438+
*/
439+
BATADV_CMD_GET_DAT_CACHE,
440+
441+
/**
442+
* @BATADV_CMD_GET_MCAST_FLAGS: Query list of multicast flags
443+
*/
444+
BATADV_CMD_GET_MCAST_FLAGS,
445+
364446
/* add new commands above here */
365447

366448
/**

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

Lines changed: 152 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
#include <linux/kernel.h>
3434
#include <linux/kref.h>
3535
#include <linux/list.h>
36+
#include <linux/netlink.h>
3637
#include <linux/rculist.h>
3738
#include <linux/rcupdate.h>
3839
#include <linux/seq_file.h>
@@ -43,13 +44,19 @@
4344
#include <linux/string.h>
4445
#include <linux/workqueue.h>
4546
#include <net/arp.h>
47+
#include <net/genetlink.h>
48+
#include <net/netlink.h>
49+
#include <net/sock.h>
50+
#include <uapi/linux/batman_adv.h>
4651

4752
#include "bridge_loop_avoidance.h"
4853
#include "hard-interface.h"
4954
#include "hash.h"
5055
#include "log.h"
56+
#include "netlink.h"
5157
#include "originator.h"
5258
#include "send.h"
59+
#include "soft-interface.h"
5360
#include "translation-table.h"
5461
#include "tvlv.h"
5562

@@ -851,6 +858,151 @@ int batadv_dat_cache_seq_print_text(struct seq_file *seq, void *offset)
851858
}
852859
#endif
853860

861+
/**
862+
* batadv_dat_cache_dump_entry() - dump one entry of the DAT cache table to a
863+
* netlink socket
864+
* @msg: buffer for the message
865+
* @portid: netlink port
866+
* @seq: Sequence number of netlink message
867+
* @dat_entry: entry to dump
868+
*
869+
* Return: 0 or error code.
870+
*/
871+
static int
872+
batadv_dat_cache_dump_entry(struct sk_buff *msg, u32 portid, u32 seq,
873+
struct batadv_dat_entry *dat_entry)
874+
{
875+
int msecs;
876+
void *hdr;
877+
878+
hdr = genlmsg_put(msg, portid, seq, &batadv_netlink_family,
879+
NLM_F_MULTI, BATADV_CMD_GET_DAT_CACHE);
880+
if (!hdr)
881+
return -ENOBUFS;
882+
883+
msecs = jiffies_to_msecs(jiffies - dat_entry->last_update);
884+
885+
if (nla_put_in_addr(msg, BATADV_ATTR_DAT_CACHE_IP4ADDRESS,
886+
dat_entry->ip) ||
887+
nla_put(msg, BATADV_ATTR_DAT_CACHE_HWADDRESS, ETH_ALEN,
888+
dat_entry->mac_addr) ||
889+
nla_put_u16(msg, BATADV_ATTR_DAT_CACHE_VID, dat_entry->vid) ||
890+
nla_put_u32(msg, BATADV_ATTR_LAST_SEEN_MSECS, msecs)) {
891+
genlmsg_cancel(msg, hdr);
892+
return -EMSGSIZE;
893+
}
894+
895+
genlmsg_end(msg, hdr);
896+
return 0;
897+
}
898+
899+
/**
900+
* batadv_dat_cache_dump_bucket() - dump one bucket of the DAT cache table to
901+
* a netlink socket
902+
* @msg: buffer for the message
903+
* @portid: netlink port
904+
* @seq: Sequence number of netlink message
905+
* @head: bucket to dump
906+
* @idx_skip: How many entries to skip
907+
*
908+
* Return: 0 or error code.
909+
*/
910+
static int
911+
batadv_dat_cache_dump_bucket(struct sk_buff *msg, u32 portid, u32 seq,
912+
struct hlist_head *head, int *idx_skip)
913+
{
914+
struct batadv_dat_entry *dat_entry;
915+
int idx = 0;
916+
917+
rcu_read_lock();
918+
hlist_for_each_entry_rcu(dat_entry, head, hash_entry) {
919+
if (idx < *idx_skip)
920+
goto skip;
921+
922+
if (batadv_dat_cache_dump_entry(msg, portid, seq,
923+
dat_entry)) {
924+
rcu_read_unlock();
925+
*idx_skip = idx;
926+
927+
return -EMSGSIZE;
928+
}
929+
930+
skip:
931+
idx++;
932+
}
933+
rcu_read_unlock();
934+
935+
return 0;
936+
}
937+
938+
/**
939+
* batadv_dat_cache_dump() - dump DAT cache table to a netlink socket
940+
* @msg: buffer for the message
941+
* @cb: callback structure containing arguments
942+
*
943+
* Return: message length.
944+
*/
945+
int batadv_dat_cache_dump(struct sk_buff *msg, struct netlink_callback *cb)
946+
{
947+
struct batadv_hard_iface *primary_if = NULL;
948+
int portid = NETLINK_CB(cb->skb).portid;
949+
struct net *net = sock_net(cb->skb->sk);
950+
struct net_device *soft_iface;
951+
struct batadv_hashtable *hash;
952+
struct batadv_priv *bat_priv;
953+
int bucket = cb->args[0];
954+
struct hlist_head *head;
955+
int idx = cb->args[1];
956+
int ifindex;
957+
int ret = 0;
958+
959+
ifindex = batadv_netlink_get_ifindex(cb->nlh,
960+
BATADV_ATTR_MESH_IFINDEX);
961+
if (!ifindex)
962+
return -EINVAL;
963+
964+
soft_iface = dev_get_by_index(net, ifindex);
965+
if (!soft_iface || !batadv_softif_is_valid(soft_iface)) {
966+
ret = -ENODEV;
967+
goto out;
968+
}
969+
970+
bat_priv = netdev_priv(soft_iface);
971+
hash = bat_priv->dat.hash;
972+
973+
primary_if = batadv_primary_if_get_selected(bat_priv);
974+
if (!primary_if || primary_if->if_status != BATADV_IF_ACTIVE) {
975+
ret = -ENOENT;
976+
goto out;
977+
}
978+
979+
while (bucket < hash->size) {
980+
head = &hash->table[bucket];
981+
982+
if (batadv_dat_cache_dump_bucket(msg, portid,
983+
cb->nlh->nlmsg_seq, head,
984+
&idx))
985+
break;
986+
987+
bucket++;
988+
idx = 0;
989+
}
990+
991+
cb->args[0] = bucket;
992+
cb->args[1] = idx;
993+
994+
ret = msg->len;
995+
996+
out:
997+
if (primary_if)
998+
batadv_hardif_put(primary_if);
999+
1000+
if (soft_iface)
1001+
dev_put(soft_iface);
1002+
1003+
return ret;
1004+
}
1005+
8541006
/**
8551007
* batadv_arp_get_type() - parse an ARP packet and gets the type
8561008
* @bat_priv: the bat priv with all the soft interface information

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828

2929
#include "originator.h"
3030

31+
struct netlink_callback;
3132
struct seq_file;
3233
struct sk_buff;
3334

@@ -81,6 +82,7 @@ batadv_dat_init_own_addr(struct batadv_priv *bat_priv,
8182
int batadv_dat_init(struct batadv_priv *bat_priv);
8283
void batadv_dat_free(struct batadv_priv *bat_priv);
8384
int batadv_dat_cache_seq_print_text(struct seq_file *seq, void *offset);
85+
int batadv_dat_cache_dump(struct sk_buff *msg, struct netlink_callback *cb);
8486

8587
/**
8688
* batadv_dat_inc_counter() - increment the correct DAT packet counter
@@ -169,6 +171,12 @@ static inline void batadv_dat_free(struct batadv_priv *bat_priv)
169171
{
170172
}
171173

174+
static inline int
175+
batadv_dat_cache_dump(struct sk_buff *msg, struct netlink_callback *cb)
176+
{
177+
return -EOPNOTSUPP;
178+
}
179+
172180
static inline void batadv_dat_inc_counter(struct batadv_priv *bat_priv,
173181
u8 subtype)
174182
{

0 commit comments

Comments
 (0)