Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 6a0e9fa8 authored by Marek Lindner's avatar Marek Lindner Committed by Greg Kroah-Hartman
Browse files

Staging: batman-adv: attach each hard-interface to a soft-interface



This patch replaces the static bat0 interface with a dynamic/abstracted
approach. It is now possible to create multiple batX interfaces by
assigning hard interfaces to them. Each batX interface acts as an
independent mesh network. A soft interface is removed once no hard
interface references it any longer.

Signed-off-by: default avatarMarek Lindner <lindner_marek@yahoo.de>
[sven.eckelmann@gmx.de: Rework on top of current version]
Signed-off-by: default avatarSven Eckelmann <sven.eckelmann@gmx.de>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@suse.de>
parent bf3264f6
Loading
Loading
Loading
Loading
+5 −8
Original line number Diff line number Diff line
@@ -97,18 +97,15 @@ static bool can_aggregate_with(struct batman_packet *new_batman_packet,

#define atomic_dec_not_zero(v)          atomic_add_unless((v), -1, 0)
/* create a new aggregated packet and add this packet to it */
static void new_aggregated_packet(unsigned char *packet_buff,
			   int packet_len,
			   unsigned long send_time,
			   bool direct_link,
static void new_aggregated_packet(unsigned char *packet_buff, int packet_len,
				  unsigned long send_time, bool direct_link,
				  struct batman_if *if_incoming,
				  int own_packet)
{
	struct forw_packet *forw_packet_aggr;
	unsigned long flags;
	unsigned char *skb_buff;
	/* FIXME: each batman_if will be attached to a softif */
	struct bat_priv *bat_priv = netdev_priv(soft_device);
	struct bat_priv *bat_priv = netdev_priv(if_incoming->soft_iface);

	/* own packet should always be scheduled */
	if (!own_packet) {
+25 −34
Original line number Diff line number Diff line
@@ -180,9 +180,7 @@ static ssize_t store_frag(struct kobject *kobj, struct attribute *attr,
		 frag_enabled_tmp == 1 ? "enabled" : "disabled");

	atomic_set(&bat_priv->frag_enabled, (unsigned)frag_enabled_tmp);

	update_min_mtu();

	update_min_mtu(net_dev);
	return count;
}

@@ -358,20 +356,6 @@ int sysfs_add_meshif(struct net_device *dev)
	struct bat_attribute **bat_attr;
	int err;

	/* FIXME: should be done in the general mesh setup
		  routine as soon as we have it */
	atomic_set(&bat_priv->aggregation_enabled, 1);
	atomic_set(&bat_priv->bonding_enabled, 0);
	atomic_set(&bat_priv->frag_enabled, 1);
	atomic_set(&bat_priv->vis_mode, VIS_TYPE_CLIENT_UPDATE);
	atomic_set(&bat_priv->orig_interval, 1000);
	atomic_set(&bat_priv->log_level, 0);
	atomic_set(&bat_priv->bcast_queue_left, BCAST_QUEUE_LEN);
	atomic_set(&bat_priv->batman_queue_left, BATMAN_QUEUE_LEN);

	bat_priv->primary_if = NULL;
	bat_priv->num_ifaces = 0;

	bat_priv->mesh_obj = kobject_create_and_add(SYSFS_IF_MESH_SUBDIR,
						    batif_kobject);
	if (!bat_priv->mesh_obj) {
@@ -441,32 +425,39 @@ static ssize_t store_mesh_iface(struct kobject *kobj, struct attribute *attr,
	if (!batman_if)
		return count;

	if (strncmp(buff, "none", 4) == 0)
		status_tmp = IF_NOT_IN_USE;

	if (strncmp(buff, "bat0", 4) == 0)
		status_tmp = IF_I_WANT_YOU;

	if (status_tmp < 0) {
	if (buff[count - 1] == '\n')
		buff[count - 1] = '\0';

	if (strlen(buff) >= IFNAMSIZ) {
		pr_err("Invalid parameter for 'mesh_iface' setting received: "
		       "%s\n", buff);
		       "interface name too long '%s'\n", buff);
		return -EINVAL;
	}

	if ((batman_if->if_status == status_tmp) ||
	    ((status_tmp == IF_I_WANT_YOU) &&
	     (batman_if->if_status != IF_NOT_IN_USE)))
	if (strncmp(buff, "none", 4) == 0)
		status_tmp = IF_NOT_IN_USE;
	else
		status_tmp = IF_I_WANT_YOU;

	if ((batman_if->if_status == status_tmp) || ((batman_if->soft_iface) &&
	    (strncmp(batman_if->soft_iface->name, buff, IFNAMSIZ) == 0)))
		return count;

	if (status_tmp == IF_I_WANT_YOU)
		status_tmp = hardif_enable_interface(batman_if);
	else
	if (status_tmp == IF_NOT_IN_USE) {
		rtnl_lock();
		hardif_disable_interface(batman_if);
		rtnl_unlock();
		return count;
	}

	/* if the interface already is in use */
	if (batman_if->if_status != IF_NOT_IN_USE) {
		rtnl_lock();
		hardif_disable_interface(batman_if);
		rtnl_unlock();
	}

	return (status_tmp < 0 ? status_tmp : count);
	return hardif_enable_interface(batman_if, buff);
}

static ssize_t show_iface_status(struct kobject *kobj, struct attribute *attr,
+3 −4
Original line number Diff line number Diff line
@@ -127,11 +127,10 @@ static void bit_reset_window(TYPE_OF_WORD *seq_bits)
 *  1 if the window was moved (either new or very old)
 *  0 if the window was not moved/shifted.
 */
char bit_get_packet(TYPE_OF_WORD *seq_bits, int32_t seq_num_diff,
		    int8_t set_mark)
char bit_get_packet(void *priv, TYPE_OF_WORD *seq_bits,
		    int32_t seq_num_diff, int8_t set_mark)
{
	/* FIXME: each orig_node->batman_if will be attached to a softif */
	struct bat_priv *bat_priv = netdev_priv(soft_device);
	struct bat_priv *bat_priv = (struct bat_priv *)priv;

	/* sequence number is slightly older. We already got a sequence number
	 * higher than this one, so we just mark it. */
+2 −2
Original line number Diff line number Diff line
@@ -38,8 +38,8 @@ void bit_mark(TYPE_OF_WORD *seq_bits, int32_t n);

/* receive and process one packet, returns 1 if received seq_num is considered
 * new, 0 if old  */
char bit_get_packet(TYPE_OF_WORD *seq_bits, int32_t seq_num_diff,
					int8_t set_mark);
char bit_get_packet(void *priv, TYPE_OF_WORD *seq_bits,
		    int32_t seq_num_diff, int8_t set_mark);

/* count the hamming weight, how many good packets did we receive? */
int  bit_packet_count(TYPE_OF_WORD *seq_bits);
+81 −50
Original line number Diff line number Diff line
@@ -128,9 +128,6 @@ static bool hardif_is_iface_up(struct batman_if *batman_if)

static void update_mac_addresses(struct batman_if *batman_if)
{
	if (!batman_if || !batman_if->packet_buff)
		return;

	addr_to_string(batman_if->addr_str, batman_if->net_dev->dev_addr);

	memcpy(((struct batman_packet *)(batman_if->packet_buff))->orig,
@@ -160,22 +157,26 @@ static void check_known_mac_addr(uint8_t *addr)
	rcu_read_unlock();
}

int hardif_min_mtu(void)
int hardif_min_mtu(struct net_device *soft_iface)
{
	struct bat_priv *bat_priv = netdev_priv(soft_iface);
	struct batman_if *batman_if;
	/* allow big frames if all devices are capable to do so
	 * (have MTU > 1500 + BAT_HEADER_LEN) */
	int min_mtu = ETH_DATA_LEN;
	/* FIXME: each batman_if will be attached to a softif */
	struct bat_priv *bat_priv = netdev_priv(soft_device);

	if (atomic_read(&bat_priv->frag_enabled))
		goto out;

	rcu_read_lock();
	list_for_each_entry_rcu(batman_if, &if_list, list) {
		if ((batman_if->if_status == IF_ACTIVE) ||
		    (batman_if->if_status == IF_TO_BE_ACTIVATED))
		if ((batman_if->if_status != IF_ACTIVE) &&
		    (batman_if->if_status != IF_TO_BE_ACTIVATED))
			continue;

		if (batman_if->soft_iface != soft_iface)
			continue;

		min_mtu = MIN(batman_if->net_dev->mtu - BAT_HEADER_LEN,
			      min_mtu);
	}
@@ -185,22 +186,24 @@ int hardif_min_mtu(void)
}

/* adjusts the MTU if a new interface with a smaller MTU appeared. */
void update_min_mtu(void)
void update_min_mtu(struct net_device *soft_iface)
{
	int min_mtu;

	min_mtu = hardif_min_mtu();
	if (soft_device->mtu != min_mtu)
		soft_device->mtu = min_mtu;
	min_mtu = hardif_min_mtu(soft_iface);
	if (soft_iface->mtu != min_mtu)
		soft_iface->mtu = min_mtu;
}

static void hardif_activate_interface(struct net_device *net_dev,
				      struct bat_priv *bat_priv,
				      struct batman_if *batman_if)
static void hardif_activate_interface(struct batman_if *batman_if)
{
	struct bat_priv *bat_priv;

	if (batman_if->if_status != IF_INACTIVE)
		return;

	bat_priv = netdev_priv(batman_if->soft_iface);

	update_mac_addresses(batman_if);
	batman_if->if_status = IF_TO_BE_ACTIVATED;

@@ -211,17 +214,17 @@ static void hardif_activate_interface(struct net_device *net_dev,
	if (!bat_priv->primary_if)
		set_primary_if(bat_priv, batman_if);

	bat_info(net_dev, "Interface activated: %s\n", batman_if->dev);
	bat_info(batman_if->soft_iface, "Interface activated: %s\n",
		 batman_if->dev);

	if (atomic_read(&module_state) == MODULE_INACTIVE)
		activate_module();

	update_min_mtu();
	update_min_mtu(batman_if->soft_iface);
	return;
}

static void hardif_deactivate_interface(struct net_device *net_dev,
					struct batman_if *batman_if)
static void hardif_deactivate_interface(struct batman_if *batman_if)
{
	if ((batman_if->if_status != IF_ACTIVE) &&
	   (batman_if->if_status != IF_TO_BE_ACTIVATED))
@@ -229,26 +232,39 @@ static void hardif_deactivate_interface(struct net_device *net_dev,

	batman_if->if_status = IF_INACTIVE;

	bat_info(net_dev, "Interface deactivated: %s\n", batman_if->dev);
	bat_info(batman_if->soft_iface, "Interface deactivated: %s\n",
		 batman_if->dev);

	update_min_mtu();
	update_min_mtu(batman_if->soft_iface);
}

int hardif_enable_interface(struct batman_if *batman_if)
int hardif_enable_interface(struct batman_if *batman_if, char *iface_name)
{
	/* FIXME: each batman_if will be attached to a softif */
	struct bat_priv *bat_priv = netdev_priv(soft_device);
	struct bat_priv *bat_priv;
	struct batman_packet *batman_packet;

	if (batman_if->if_status != IF_NOT_IN_USE)
		goto out;

	batman_if->soft_iface = dev_get_by_name(&init_net, iface_name);

	if (!batman_if->soft_iface) {
		batman_if->soft_iface = softif_create(iface_name);

		if (!batman_if->soft_iface)
			goto err;

		/* dev_get_by_name() increases the reference counter for us */
		dev_hold(batman_if->soft_iface);
	}

	bat_priv = netdev_priv(batman_if->soft_iface);
	batman_if->packet_len = BAT_PACKET_LEN;
	batman_if->packet_buff = kmalloc(batman_if->packet_len, GFP_ATOMIC);

	if (!batman_if->packet_buff) {
		bat_err(soft_device, "Can't add interface packet (%s): "
			"out of memory\n", batman_if->dev);
		bat_err(batman_if->soft_iface, "Can't add interface packet "
			"(%s): out of memory\n", batman_if->dev);
		goto err;
	}

@@ -272,11 +288,12 @@ int hardif_enable_interface(struct batman_if *batman_if)

	atomic_set(&batman_if->seqno, 1);
	atomic_set(&batman_if->frag_seqno, 1);
	bat_info(soft_device, "Adding interface: %s\n", batman_if->dev);
	bat_info(batman_if->soft_iface, "Adding interface: %s\n",
		 batman_if->dev);

	if (atomic_read(&bat_priv->frag_enabled) && batman_if->net_dev->mtu <
		ETH_DATA_LEN + BAT_HEADER_LEN)
		bat_info(soft_device,
		bat_info(batman_if->soft_iface,
			"The MTU of interface %s is too small (%i) to handle "
			"the transport of batman-adv packets. Packets going "
			"over this interface will be fragmented on layer2 "
@@ -287,7 +304,7 @@ int hardif_enable_interface(struct batman_if *batman_if)

	if (!atomic_read(&bat_priv->frag_enabled) && batman_if->net_dev->mtu <
		ETH_DATA_LEN + BAT_HEADER_LEN)
		bat_info(soft_device,
		bat_info(batman_if->soft_iface,
			"The MTU of interface %s is too small (%i) to handle "
			"the transport of batman-adv packets. If you experience"
			" problems getting traffic through try increasing the "
@@ -296,9 +313,9 @@ int hardif_enable_interface(struct batman_if *batman_if)
			ETH_DATA_LEN + BAT_HEADER_LEN);

	if (hardif_is_iface_up(batman_if))
		hardif_activate_interface(soft_device, bat_priv, batman_if);
		hardif_activate_interface(batman_if);
	else
		bat_err(soft_device, "Not using interface %s "
		bat_err(batman_if->soft_iface, "Not using interface %s "
			"(retrying later): interface not active\n",
			batman_if->dev);

@@ -314,16 +331,16 @@ int hardif_enable_interface(struct batman_if *batman_if)

void hardif_disable_interface(struct batman_if *batman_if)
{
	/* FIXME: each batman_if will be attached to a softif */
	struct bat_priv *bat_priv = netdev_priv(soft_device);
	struct bat_priv *bat_priv = netdev_priv(batman_if->soft_iface);

	if (batman_if->if_status == IF_ACTIVE)
		hardif_deactivate_interface(soft_device, batman_if);
		hardif_deactivate_interface(batman_if);

	if (batman_if->if_status != IF_INACTIVE)
		return;

	bat_info(soft_device, "Removing interface: %s\n", batman_if->dev);
	bat_info(batman_if->soft_iface, "Removing interface: %s\n",
		 batman_if->dev);
	dev_remove_pack(&batman_if->batman_adv_ptype);

	bat_priv->num_ifaces--;
@@ -335,10 +352,17 @@ void hardif_disable_interface(struct batman_if *batman_if)
	kfree(batman_if->packet_buff);
	batman_if->packet_buff = NULL;
	batman_if->if_status = IF_NOT_IN_USE;
	dev_put(batman_if->soft_iface);

	if ((atomic_read(&module_state) == MODULE_ACTIVE) &&
	/* nobody uses this interface anymore */
	if (!bat_priv->num_ifaces)
		softif_destroy(batman_if->soft_iface);

	batman_if->soft_iface = NULL;

	/*if ((atomic_read(&module_state) == MODULE_ACTIVE) &&
	    (bat_priv->num_ifaces == 0))
		deactivate_module();
		deactivate_module();*/
}

static struct batman_if *hardif_add_interface(struct net_device *net_dev)
@@ -369,8 +393,8 @@ static struct batman_if *hardif_add_interface(struct net_device *net_dev)

	batman_if->if_num = -1;
	batman_if->net_dev = net_dev;
	batman_if->soft_iface = NULL;
	batman_if->if_status = IF_NOT_IN_USE;
	batman_if->packet_buff = NULL;
	INIT_LIST_HEAD(&batman_if->list);

	check_known_mac_addr(batman_if->net_dev->dev_addr);
@@ -419,8 +443,11 @@ void hardif_remove_interfaces(void)
{
	struct batman_if *batman_if, *batman_if_tmp;

	list_for_each_entry_safe(batman_if, batman_if_tmp, &if_list, list)
	list_for_each_entry_safe(batman_if, batman_if_tmp, &if_list, list) {
		rtnl_lock();
		hardif_remove_interface(batman_if);
		rtnl_unlock();
	}
}

static int hard_if_event(struct notifier_block *this,
@@ -428,8 +455,7 @@ static int hard_if_event(struct notifier_block *this,
{
	struct net_device *net_dev = (struct net_device *)ptr;
	struct batman_if *batman_if = get_batman_if_by_netdev(net_dev);
	/* FIXME: each batman_if will be attached to a softif */
	struct bat_priv *bat_priv = netdev_priv(soft_device);
	struct bat_priv *bat_priv;

	if (!batman_if && event == NETDEV_REGISTER)
			batman_if = hardif_add_interface(net_dev);
@@ -439,11 +465,11 @@ static int hard_if_event(struct notifier_block *this,

	switch (event) {
	case NETDEV_UP:
		hardif_activate_interface(soft_device, bat_priv, batman_if);
		hardif_activate_interface(batman_if);
		break;
	case NETDEV_GOING_DOWN:
	case NETDEV_DOWN:
		hardif_deactivate_interface(soft_device, batman_if);
		hardif_deactivate_interface(batman_if);
		break;
	case NETDEV_UNREGISTER:
		hardif_remove_interface(batman_if);
@@ -451,8 +477,13 @@ static int hard_if_event(struct notifier_block *this,
	case NETDEV_CHANGENAME:
		break;
	case NETDEV_CHANGEADDR:
		if (batman_if->if_status == IF_NOT_IN_USE)
			goto out;

		check_known_mac_addr(batman_if->net_dev->dev_addr);
		update_mac_addresses(batman_if);

		bat_priv = netdev_priv(batman_if->soft_iface);
		if (batman_if == bat_priv->primary_if)
			set_primary_if(bat_priv, batman_if);
		break;
@@ -469,8 +500,7 @@ static int hard_if_event(struct notifier_block *this,
int batman_skb_recv(struct sk_buff *skb, struct net_device *dev,
	struct packet_type *ptype, struct net_device *orig_dev)
{
	/* FIXME: each orig_node->batman_if will be attached to a softif */
	struct bat_priv *bat_priv = netdev_priv(soft_device);
	struct bat_priv *bat_priv;
	struct batman_packet *batman_packet;
	struct batman_if *batman_if;
	int ret;
@@ -499,6 +529,7 @@ int batman_skb_recv(struct sk_buff *skb, struct net_device *dev,
		goto err_free;

	batman_packet = (struct batman_packet *)skb->data;
	bat_priv = netdev_priv(batman_if->soft_iface);

	if (batman_packet->version != COMPAT_VERSION) {
		bat_dbg(DBG_BATMAN, bat_priv,
@@ -518,7 +549,7 @@ int batman_skb_recv(struct sk_buff *skb, struct net_device *dev,

		/* batman icmp packet */
	case BAT_ICMP:
		ret = recv_icmp_packet(skb);
		ret = recv_icmp_packet(skb, batman_if);
		break;

		/* unicast packet */
@@ -533,12 +564,12 @@ int batman_skb_recv(struct sk_buff *skb, struct net_device *dev,

		/* broadcast packet */
	case BAT_BCAST:
		ret = recv_bcast_packet(skb);
		ret = recv_bcast_packet(skb, batman_if);
		break;

		/* vis packet */
	case BAT_VIS:
		ret = recv_vis_packet(skb);
		ret = recv_vis_packet(skb, batman_if);
		break;
	default:
		ret = NET_RX_DROP;
Loading