Skip to content

Commit

Permalink
Merge tag 'batadv-next-for-davem-20180319' of git://git.open-mesh.org…
Browse files Browse the repository at this point in the history
…/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 <davem@davemloft.net>
  • Loading branch information
David S. Miller committed Mar 22, 2018
2 parents bdf5bd7 + 53dd9a6 commit 755f663
Show file tree
Hide file tree
Showing 6 changed files with 604 additions and 37 deletions.
82 changes: 82 additions & 0 deletions include/uapi/linux/batman_adv.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,53 @@ enum batadv_tt_client_flags {
BATADV_TT_CLIENT_TEMP = (1 << 11),
};

/**
* enum batadv_mcast_flags_priv - Private, own multicast flags
*
* These are internal, multicast related flags. Currently they describe certain
* multicast related attributes of the segment this originator bridges into the
* mesh.
*
* Those attributes are used to determine the public multicast flags this
* originator is going to announce via TT.
*
* For netlink, if BATADV_MCAST_FLAGS_BRIDGED is unset then all querier
* related flags are undefined.
*/
enum batadv_mcast_flags_priv {
/**
* @BATADV_MCAST_FLAGS_BRIDGED: There is a bridge on top of the mesh
* interface.
*/
BATADV_MCAST_FLAGS_BRIDGED = (1 << 0),

/**
* @BATADV_MCAST_FLAGS_QUERIER_IPV4_EXISTS: Whether an IGMP querier
* exists in the mesh
*/
BATADV_MCAST_FLAGS_QUERIER_IPV4_EXISTS = (1 << 1),

/**
* @BATADV_MCAST_FLAGS_QUERIER_IPV6_EXISTS: Whether an MLD querier
* exists in the mesh
*/
BATADV_MCAST_FLAGS_QUERIER_IPV6_EXISTS = (1 << 2),

/**
* @BATADV_MCAST_FLAGS_QUERIER_IPV4_SHADOWING: If an IGMP querier
* exists, whether it is potentially shadowing multicast listeners
* (i.e. querier is behind our own bridge segment)
*/
BATADV_MCAST_FLAGS_QUERIER_IPV4_SHADOWING = (1 << 3),

/**
* @BATADV_MCAST_FLAGS_QUERIER_IPV6_SHADOWING: If an MLD querier
* exists, whether it is potentially shadowing multicast listeners
* (i.e. querier is behind our own bridge segment)
*/
BATADV_MCAST_FLAGS_QUERIER_IPV6_SHADOWING = (1 << 4),
};

/**
* enum batadv_nl_attrs - batman-adv netlink attributes
*/
Expand Down Expand Up @@ -272,6 +319,31 @@ enum batadv_nl_attrs {
*/
BATADV_ATTR_BLA_CRC,

/**
* @BATADV_ATTR_DAT_CACHE_IP4ADDRESS: Client IPv4 address
*/
BATADV_ATTR_DAT_CACHE_IP4ADDRESS,

/**
* @BATADV_ATTR_DAT_CACHE_HWADDRESS: Client MAC address
*/
BATADV_ATTR_DAT_CACHE_HWADDRESS,

/**
* @BATADV_ATTR_DAT_CACHE_VID: VLAN ID
*/
BATADV_ATTR_DAT_CACHE_VID,

/**
* @BATADV_ATTR_MCAST_FLAGS: Per originator multicast flags
*/
BATADV_ATTR_MCAST_FLAGS,

/**
* @BATADV_ATTR_MCAST_FLAGS_PRIV: Private, own multicast flags
*/
BATADV_ATTR_MCAST_FLAGS_PRIV,

/* add attributes above here, update the policy in netlink.c */

/**
Expand Down Expand Up @@ -361,6 +433,16 @@ enum batadv_nl_commands {
*/
BATADV_CMD_GET_BLA_BACKBONE,

/**
* @BATADV_CMD_GET_DAT_CACHE: Query list of DAT cache entries
*/
BATADV_CMD_GET_DAT_CACHE,

/**
* @BATADV_CMD_GET_MCAST_FLAGS: Query list of multicast flags
*/
BATADV_CMD_GET_MCAST_FLAGS,

/* add new commands above here */

/**
Expand Down
152 changes: 152 additions & 0 deletions net/batman-adv/distributed-arp-table.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
#include <linux/kernel.h>
#include <linux/kref.h>
#include <linux/list.h>
#include <linux/netlink.h>
#include <linux/rculist.h>
#include <linux/rcupdate.h>
#include <linux/seq_file.h>
Expand All @@ -43,13 +44,19 @@
#include <linux/string.h>
#include <linux/workqueue.h>
#include <net/arp.h>
#include <net/genetlink.h>
#include <net/netlink.h>
#include <net/sock.h>
#include <uapi/linux/batman_adv.h>

#include "bridge_loop_avoidance.h"
#include "hard-interface.h"
#include "hash.h"
#include "log.h"
#include "netlink.h"
#include "originator.h"
#include "send.h"
#include "soft-interface.h"
#include "translation-table.h"
#include "tvlv.h"

Expand Down Expand Up @@ -851,6 +858,151 @@ int batadv_dat_cache_seq_print_text(struct seq_file *seq, void *offset)
}
#endif

/**
* batadv_dat_cache_dump_entry() - dump one entry of the DAT cache table to a
* netlink socket
* @msg: buffer for the message
* @portid: netlink port
* @seq: Sequence number of netlink message
* @dat_entry: entry to dump
*
* Return: 0 or error code.
*/
static int
batadv_dat_cache_dump_entry(struct sk_buff *msg, u32 portid, u32 seq,
struct batadv_dat_entry *dat_entry)
{
int msecs;
void *hdr;

hdr = genlmsg_put(msg, portid, seq, &batadv_netlink_family,
NLM_F_MULTI, BATADV_CMD_GET_DAT_CACHE);
if (!hdr)
return -ENOBUFS;

msecs = jiffies_to_msecs(jiffies - dat_entry->last_update);

if (nla_put_in_addr(msg, BATADV_ATTR_DAT_CACHE_IP4ADDRESS,
dat_entry->ip) ||
nla_put(msg, BATADV_ATTR_DAT_CACHE_HWADDRESS, ETH_ALEN,
dat_entry->mac_addr) ||
nla_put_u16(msg, BATADV_ATTR_DAT_CACHE_VID, dat_entry->vid) ||
nla_put_u32(msg, BATADV_ATTR_LAST_SEEN_MSECS, msecs)) {
genlmsg_cancel(msg, hdr);
return -EMSGSIZE;
}

genlmsg_end(msg, hdr);
return 0;
}

/**
* batadv_dat_cache_dump_bucket() - dump one bucket of the DAT cache table to
* a netlink socket
* @msg: buffer for the message
* @portid: netlink port
* @seq: Sequence number of netlink message
* @head: bucket to dump
* @idx_skip: How many entries to skip
*
* Return: 0 or error code.
*/
static int
batadv_dat_cache_dump_bucket(struct sk_buff *msg, u32 portid, u32 seq,
struct hlist_head *head, int *idx_skip)
{
struct batadv_dat_entry *dat_entry;
int idx = 0;

rcu_read_lock();
hlist_for_each_entry_rcu(dat_entry, head, hash_entry) {
if (idx < *idx_skip)
goto skip;

if (batadv_dat_cache_dump_entry(msg, portid, seq,
dat_entry)) {
rcu_read_unlock();
*idx_skip = idx;

return -EMSGSIZE;
}

skip:
idx++;
}
rcu_read_unlock();

return 0;
}

/**
* batadv_dat_cache_dump() - dump DAT cache table to a netlink socket
* @msg: buffer for the message
* @cb: callback structure containing arguments
*
* Return: message length.
*/
int batadv_dat_cache_dump(struct sk_buff *msg, struct netlink_callback *cb)
{
struct batadv_hard_iface *primary_if = NULL;
int portid = NETLINK_CB(cb->skb).portid;
struct net *net = sock_net(cb->skb->sk);
struct net_device *soft_iface;
struct batadv_hashtable *hash;
struct batadv_priv *bat_priv;
int bucket = cb->args[0];
struct hlist_head *head;
int idx = cb->args[1];
int ifindex;
int ret = 0;

ifindex = batadv_netlink_get_ifindex(cb->nlh,
BATADV_ATTR_MESH_IFINDEX);
if (!ifindex)
return -EINVAL;

soft_iface = dev_get_by_index(net, ifindex);
if (!soft_iface || !batadv_softif_is_valid(soft_iface)) {
ret = -ENODEV;
goto out;
}

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

primary_if = batadv_primary_if_get_selected(bat_priv);
if (!primary_if || primary_if->if_status != BATADV_IF_ACTIVE) {
ret = -ENOENT;
goto out;
}

while (bucket < hash->size) {
head = &hash->table[bucket];

if (batadv_dat_cache_dump_bucket(msg, portid,
cb->nlh->nlmsg_seq, head,
&idx))
break;

bucket++;
idx = 0;
}

cb->args[0] = bucket;
cb->args[1] = idx;

ret = msg->len;

out:
if (primary_if)
batadv_hardif_put(primary_if);

if (soft_iface)
dev_put(soft_iface);

return ret;
}

/**
* batadv_arp_get_type() - parse an ARP packet and gets the type
* @bat_priv: the bat priv with all the soft interface information
Expand Down
8 changes: 8 additions & 0 deletions net/batman-adv/distributed-arp-table.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@

#include "originator.h"

struct netlink_callback;
struct seq_file;
struct sk_buff;

Expand Down Expand Up @@ -81,6 +82,7 @@ batadv_dat_init_own_addr(struct batadv_priv *bat_priv,
int batadv_dat_init(struct batadv_priv *bat_priv);
void batadv_dat_free(struct batadv_priv *bat_priv);
int batadv_dat_cache_seq_print_text(struct seq_file *seq, void *offset);
int batadv_dat_cache_dump(struct sk_buff *msg, struct netlink_callback *cb);

/**
* batadv_dat_inc_counter() - increment the correct DAT packet counter
Expand Down Expand Up @@ -169,6 +171,12 @@ static inline void batadv_dat_free(struct batadv_priv *bat_priv)
{
}

static inline int
batadv_dat_cache_dump(struct sk_buff *msg, struct netlink_callback *cb)
{
return -EOPNOTSUPP;
}

static inline void batadv_dat_inc_counter(struct batadv_priv *bat_priv,
u8 subtype)
{
Expand Down
Loading

0 comments on commit 755f663

Please sign in to comment.