aboutsummaryrefslogtreecommitdiffstats
path: root/net/batman-adv
diff options
context:
space:
mode:
authorAntonio Quartulli <antonio@open-mesh.com>2013-11-16 06:03:47 -0500
committerAntonio Quartulli <antonio@meshcoding.com>2014-01-08 14:49:42 -0500
commitc42edfe382fee1c2c74550a5a3cbf50b2a28cf07 (patch)
treebc1f346482e3c6f24b9363d3362e8ee691a30e4b /net/batman-adv
parent6c413b1c22a2c4ef324f1c6f2c282f1ca10a93b9 (diff)
batman-adv: add isolation_mark sysfs attribute
This attribute can be used to set and read the value and the mask of the skb mark which will be used to classify the source non-mesh client as ISOLATED. In this way a client can be advertised as such and the mark can potentially be restored at the receiving node before delivering the skb. This can be helpful for creating network wide netfilter policies. This sysfs file expects a string of the shape "$mark/$mask". Where $mark has to be a 32-bit number in any base, while $mask must be a 32bit mask expressed in hex base. Only bits in $mark covered by the bitmask are really stored. Signed-off-by: Antonio Quartulli <antonio@open-mesh.com> Signed-off-by: Marek Lindner <mareklindner@neomailbox.ch>
Diffstat (limited to 'net/batman-adv')
-rw-r--r--net/batman-adv/soft-interface.c2
-rw-r--r--net/batman-adv/sysfs.c71
-rw-r--r--net/batman-adv/types.h2
3 files changed, 75 insertions, 0 deletions
diff --git a/net/batman-adv/soft-interface.c b/net/batman-adv/soft-interface.c
index b569932ddcc4..35a82e36c003 100644
--- a/net/batman-adv/soft-interface.c
+++ b/net/batman-adv/soft-interface.c
@@ -701,6 +701,8 @@ static int batadv_softif_init_late(struct net_device *dev)
701#endif 701#endif
702 bat_priv->tt.last_changeset = NULL; 702 bat_priv->tt.last_changeset = NULL;
703 bat_priv->tt.last_changeset_len = 0; 703 bat_priv->tt.last_changeset_len = 0;
704 bat_priv->isolation_mark = 0;
705 bat_priv->isolation_mark_mask = 0;
704 706
705 /* randomize initial seqno to avoid collision */ 707 /* randomize initial seqno to avoid collision */
706 get_random_bytes(&random_seqno, sizeof(random_seqno)); 708 get_random_bytes(&random_seqno, sizeof(random_seqno));
diff --git a/net/batman-adv/sysfs.c b/net/batman-adv/sysfs.c
index 511e01175654..b6a4403b7007 100644
--- a/net/batman-adv/sysfs.c
+++ b/net/batman-adv/sysfs.c
@@ -450,6 +450,74 @@ static ssize_t batadv_store_gw_bwidth(struct kobject *kobj,
450 return batadv_gw_bandwidth_set(net_dev, buff, count); 450 return batadv_gw_bandwidth_set(net_dev, buff, count);
451} 451}
452 452
453/**
454 * batadv_show_isolation_mark - print the current isolation mark/mask
455 * @kobj: kobject representing the private mesh sysfs directory
456 * @attr: the batman-adv attribute the user is interacting with
457 * @buff: the buffer that will contain the data to send back to the user
458 *
459 * Returns the number of bytes written into 'buff' on success or a negative
460 * error code in case of failure
461 */
462static ssize_t batadv_show_isolation_mark(struct kobject *kobj,
463 struct attribute *attr, char *buff)
464{
465 struct batadv_priv *bat_priv = batadv_kobj_to_batpriv(kobj);
466
467 return sprintf(buff, "%#.8x/%#.8x\n", bat_priv->isolation_mark,
468 bat_priv->isolation_mark_mask);
469}
470
471/**
472 * batadv_store_isolation_mark - parse and store the isolation mark/mask entered
473 * by the user
474 * @kobj: kobject representing the private mesh sysfs directory
475 * @attr: the batman-adv attribute the user is interacting with
476 * @buff: the buffer containing the user data
477 * @count: number of bytes in the buffer
478 *
479 * Returns 'count' on success or a negative error code in case of failure
480 */
481static ssize_t batadv_store_isolation_mark(struct kobject *kobj,
482 struct attribute *attr, char *buff,
483 size_t count)
484{
485 struct net_device *net_dev = batadv_kobj_to_netdev(kobj);
486 struct batadv_priv *bat_priv = netdev_priv(net_dev);
487 uint32_t mark, mask;
488 char *mask_ptr;
489
490 /* parse the mask if it has been specified, otherwise assume the mask is
491 * the biggest possible
492 */
493 mask = 0xFFFFFFFF;
494 mask_ptr = strchr(buff, '/');
495 if (mask_ptr) {
496 *mask_ptr = '\0';
497 mask_ptr++;
498
499 /* the mask must be entered in hex base as it is going to be a
500 * bitmask and not a prefix length
501 */
502 if (kstrtou32(mask_ptr, 16, &mask) < 0)
503 return -EINVAL;
504 }
505
506 /* the mark can be entered in any base */
507 if (kstrtou32(buff, 0, &mark) < 0)
508 return -EINVAL;
509
510 bat_priv->isolation_mark_mask = mask;
511 /* erase bits not covered by the mask */
512 bat_priv->isolation_mark = mark & bat_priv->isolation_mark_mask;
513
514 batadv_info(net_dev,
515 "New skb mark for extended isolation: %#.8x/%#.8x\n",
516 bat_priv->isolation_mark, bat_priv->isolation_mark_mask);
517
518 return count;
519}
520
453BATADV_ATTR_SIF_BOOL(aggregated_ogms, S_IRUGO | S_IWUSR, NULL); 521BATADV_ATTR_SIF_BOOL(aggregated_ogms, S_IRUGO | S_IWUSR, NULL);
454BATADV_ATTR_SIF_BOOL(bonding, S_IRUGO | S_IWUSR, NULL); 522BATADV_ATTR_SIF_BOOL(bonding, S_IRUGO | S_IWUSR, NULL);
455#ifdef CONFIG_BATMAN_ADV_BLA 523#ifdef CONFIG_BATMAN_ADV_BLA
@@ -478,6 +546,8 @@ BATADV_ATTR_SIF_UINT(log_level, S_IRUGO | S_IWUSR, 0, BATADV_DBG_ALL, NULL);
478BATADV_ATTR_SIF_BOOL(network_coding, S_IRUGO | S_IWUSR, 546BATADV_ATTR_SIF_BOOL(network_coding, S_IRUGO | S_IWUSR,
479 batadv_nc_status_update); 547 batadv_nc_status_update);
480#endif 548#endif
549static BATADV_ATTR(isolation_mark, S_IRUGO | S_IWUSR,
550 batadv_show_isolation_mark, batadv_store_isolation_mark);
481 551
482static struct batadv_attribute *batadv_mesh_attrs[] = { 552static struct batadv_attribute *batadv_mesh_attrs[] = {
483 &batadv_attr_aggregated_ogms, 553 &batadv_attr_aggregated_ogms,
@@ -501,6 +571,7 @@ static struct batadv_attribute *batadv_mesh_attrs[] = {
501#ifdef CONFIG_BATMAN_ADV_NC 571#ifdef CONFIG_BATMAN_ADV_NC
502 &batadv_attr_network_coding, 572 &batadv_attr_network_coding,
503#endif 573#endif
574 &batadv_attr_isolation_mark,
504 NULL, 575 NULL,
505}; 576};
506 577
diff --git a/net/batman-adv/types.h b/net/batman-adv/types.h
index 70abb1c7087f..0430a0474506 100644
--- a/net/batman-adv/types.h
+++ b/net/batman-adv/types.h
@@ -697,6 +697,8 @@ struct batadv_priv {
697#ifdef CONFIG_BATMAN_ADV_DEBUG 697#ifdef CONFIG_BATMAN_ADV_DEBUG
698 atomic_t log_level; 698 atomic_t log_level;
699#endif 699#endif
700 uint32_t isolation_mark;
701 uint32_t isolation_mark_mask;
700 atomic_t bcast_seqno; 702 atomic_t bcast_seqno;
701 atomic_t bcast_queue_left; 703 atomic_t bcast_queue_left;
702 atomic_t batman_queue_left; 704 atomic_t batman_queue_left;