~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/net/batman-adv/gateway_common.c

Version: ~ [ linux-6.11.5 ] ~ [ linux-6.10.14 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.58 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.114 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.169 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.228 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.284 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.322 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.336 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.337 ] ~ [ linux-4.4.302 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.9 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 // SPDX-License-Identifier: GPL-2.0
  2 /* Copyright (C) B.A.T.M.A.N. contributors:
  3  *
  4  * Marek Lindner
  5  */
  6 
  7 #include "gateway_common.h"
  8 #include "main.h"
  9 
 10 #include <linux/atomic.h>
 11 #include <linux/byteorder/generic.h>
 12 #include <linux/stddef.h>
 13 #include <linux/types.h>
 14 #include <uapi/linux/batadv_packet.h>
 15 #include <uapi/linux/batman_adv.h>
 16 
 17 #include "gateway_client.h"
 18 #include "tvlv.h"
 19 
 20 /**
 21  * batadv_gw_tvlv_container_update() - update the gw tvlv container after
 22  *  gateway setting change
 23  * @bat_priv: the bat priv with all the soft interface information
 24  */
 25 void batadv_gw_tvlv_container_update(struct batadv_priv *bat_priv)
 26 {
 27         struct batadv_tvlv_gateway_data gw;
 28         u32 down, up;
 29         char gw_mode;
 30 
 31         gw_mode = atomic_read(&bat_priv->gw.mode);
 32 
 33         switch (gw_mode) {
 34         case BATADV_GW_MODE_OFF:
 35         case BATADV_GW_MODE_CLIENT:
 36                 batadv_tvlv_container_unregister(bat_priv, BATADV_TVLV_GW, 1);
 37                 break;
 38         case BATADV_GW_MODE_SERVER:
 39                 down = atomic_read(&bat_priv->gw.bandwidth_down);
 40                 up = atomic_read(&bat_priv->gw.bandwidth_up);
 41                 gw.bandwidth_down = htonl(down);
 42                 gw.bandwidth_up = htonl(up);
 43                 batadv_tvlv_container_register(bat_priv, BATADV_TVLV_GW, 1,
 44                                                &gw, sizeof(gw));
 45                 break;
 46         }
 47 }
 48 
 49 /**
 50  * batadv_gw_tvlv_ogm_handler_v1() - process incoming gateway tvlv container
 51  * @bat_priv: the bat priv with all the soft interface information
 52  * @orig: the orig_node of the ogm
 53  * @flags: flags indicating the tvlv state (see batadv_tvlv_handler_flags)
 54  * @tvlv_value: tvlv buffer containing the gateway data
 55  * @tvlv_value_len: tvlv buffer length
 56  */
 57 static void batadv_gw_tvlv_ogm_handler_v1(struct batadv_priv *bat_priv,
 58                                           struct batadv_orig_node *orig,
 59                                           u8 flags,
 60                                           void *tvlv_value, u16 tvlv_value_len)
 61 {
 62         struct batadv_tvlv_gateway_data gateway, *gateway_ptr;
 63 
 64         /* only fetch the tvlv value if the handler wasn't called via the
 65          * CIFNOTFND flag and if there is data to fetch
 66          */
 67         if (flags & BATADV_TVLV_HANDLER_OGM_CIFNOTFND ||
 68             tvlv_value_len < sizeof(gateway)) {
 69                 gateway.bandwidth_down = 0;
 70                 gateway.bandwidth_up = 0;
 71         } else {
 72                 gateway_ptr = tvlv_value;
 73                 gateway.bandwidth_down = gateway_ptr->bandwidth_down;
 74                 gateway.bandwidth_up = gateway_ptr->bandwidth_up;
 75                 if (gateway.bandwidth_down == 0 ||
 76                     gateway.bandwidth_up == 0) {
 77                         gateway.bandwidth_down = 0;
 78                         gateway.bandwidth_up = 0;
 79                 }
 80         }
 81 
 82         batadv_gw_node_update(bat_priv, orig, &gateway);
 83 
 84         /* restart gateway selection */
 85         if (gateway.bandwidth_down != 0 &&
 86             atomic_read(&bat_priv->gw.mode) == BATADV_GW_MODE_CLIENT)
 87                 batadv_gw_check_election(bat_priv, orig);
 88 }
 89 
 90 /**
 91  * batadv_gw_init() - initialise the gateway handling internals
 92  * @bat_priv: the bat priv with all the soft interface information
 93  */
 94 void batadv_gw_init(struct batadv_priv *bat_priv)
 95 {
 96         if (bat_priv->algo_ops->gw.init_sel_class)
 97                 bat_priv->algo_ops->gw.init_sel_class(bat_priv);
 98         else
 99                 atomic_set(&bat_priv->gw.sel_class, 1);
100 
101         batadv_tvlv_handler_register(bat_priv, batadv_gw_tvlv_ogm_handler_v1,
102                                      NULL, NULL, BATADV_TVLV_GW, 1,
103                                      BATADV_TVLV_HANDLER_OGM_CIFNOTFND);
104 }
105 
106 /**
107  * batadv_gw_free() - free the gateway handling internals
108  * @bat_priv: the bat priv with all the soft interface information
109  */
110 void batadv_gw_free(struct batadv_priv *bat_priv)
111 {
112         batadv_tvlv_container_unregister(bat_priv, BATADV_TVLV_GW, 1);
113         batadv_tvlv_handler_unregister(bat_priv, BATADV_TVLV_GW, 1);
114 }
115 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

sflogo.php