/* List manipulations on hardif_list have to be rtnl_lock()'ed, * list traversals just rcu-locked
*/ struct list_head batadv_hardif_list; unsignedint batadv_hardif_generation; staticint (*batadv_rx_handler[256])(struct sk_buff *skb, struct batadv_hard_iface *recv_if);
/** * batadv_mesh_init() - Initialize mesh interface * @mesh_iface: netdev struct of the mesh interface * * Return: 0 on success or negative error number in case of failure
*/ int batadv_mesh_init(struct net_device *mesh_iface)
{ struct batadv_priv *bat_priv = netdev_priv(mesh_iface); int ret;
/* Free the TT and the originator tables only after having terminated * all the other depending components which may use these structures for * their purposes.
*/
batadv_tt_free(bat_priv);
/* Since the originator table clean up routine is accessing the TT * tables as well, it has to be invoked after the TT tables have been * freed and marked as empty. This ensures that no cleanup RCU callbacks * accessing the TT data are scheduled for later execution.
*/
batadv_originator_free(bat_priv);
/** * batadv_is_my_mac() - check if the given mac address belongs to any of the * real interfaces in the current mesh * @bat_priv: the bat priv with all the mesh interface information * @addr: the address to check * * Return: 'true' if the mac address was found, false otherwise.
*/ bool batadv_is_my_mac(struct batadv_priv *bat_priv, const u8 *addr)
{ conststruct batadv_hard_iface *hard_iface; struct list_head *iter; bool is_my_mac = false;
rcu_read_lock();
netdev_for_each_lower_private_rcu(bat_priv->mesh_iface, hard_iface, iter) { if (hard_iface->if_status != BATADV_IF_ACTIVE) continue;
/** * batadv_max_header_len() - calculate maximum encapsulation overhead for a * payload packet * * Return: the maximum encapsulation overhead in bytes.
*/ int batadv_max_header_len(void)
{ int header_len = 0;
/** * batadv_skb_set_priority() - sets skb priority according to packet content * @skb: the packet to be sent * @offset: offset to the packet content * * This function sets a value between 256 and 263 (802.1d priority), which * can be interpreted by the cfg80211 or other drivers.
*/ void batadv_skb_set_priority(struct sk_buff *skb, int offset)
{ struct iphdr ip_hdr_tmp, *ip_hdr; struct ipv6hdr ip6_hdr_tmp, *ip6_hdr; struct ethhdr ethhdr_tmp, *ethhdr; struct vlan_ethhdr *vhdr, vhdr_tmp;
u32 prio;
/* already set, do nothing */ if (skb->priority >= 256 && skb->priority <= 263) return;
ethhdr = skb_header_pointer(skb, offset, sizeof(*ethhdr), ðhdr_tmp); if (!ethhdr) return;
/* incoming packets with the batman ethertype received on any active hard * interface
*/
/** * batadv_batman_skb_recv() - Handle incoming message from an hard interface * @skb: the received packet * @dev: the net device that the packet was received on * @ptype: packet type of incoming packet (ETH_P_BATMAN) * @orig_dev: the original receive net device (e.g. bonded device) * * Return: NET_RX_SUCCESS on success or NET_RX_DROP in case of failure
*/ int batadv_batman_skb_recv(struct sk_buff *skb, struct net_device *dev, struct packet_type *ptype, struct net_device *orig_dev)
{ struct batadv_priv *bat_priv; struct batadv_ogm_packet *batadv_ogm_packet; struct batadv_hard_iface *hard_iface;
u8 idx;
/* Prevent processing a packet received on an interface which is getting * shut down otherwise the packet may trigger de-reference errors * further down in the receive path.
*/ if (!kref_get_unless_zero(&hard_iface->refcount)) goto err_out;
skb = skb_share_check(skb, GFP_ATOMIC);
/* skb was released by skb_share_check() */ if (!skb) goto err_put;
/* packet should hold at least type and version */ if (unlikely(!pskb_may_pull(skb, 2))) goto err_free;
/* expect a valid ethernet header here. */ if (unlikely(skb->mac_len != ETH_HLEN || !skb_mac_header(skb))) goto err_free;
if (!hard_iface->mesh_iface) goto err_free;
bat_priv = netdev_priv(hard_iface->mesh_iface);
if (atomic_read(&bat_priv->mesh_state) != BATADV_MESH_ACTIVE) goto err_free;
/* discard frames on not active interfaces */ if (hard_iface->if_status != BATADV_IF_ACTIVE) goto err_free;
/** * batadv_recv_handler_register() - Register handler for batman-adv packet type * @packet_type: batadv_packettype which should be handled * @recv_handler: receive handler for the packet type * * Return: 0 on success or negative error number in case of failure
*/ int
batadv_recv_handler_register(u8 packet_type, int (*recv_handler)(struct sk_buff *, struct batadv_hard_iface *))
{ int (*curr)(struct sk_buff *skb, struct batadv_hard_iface *recv_if);
curr = batadv_rx_handler[packet_type];
if (curr != batadv_recv_unhandled_packet &&
curr != batadv_recv_unhandled_unicast_packet) return -EBUSY;
/** * batadv_recv_handler_unregister() - Unregister handler for packet type * @packet_type: batadv_packettype which should no longer be handled
*/ void batadv_recv_handler_unregister(u8 packet_type)
{
batadv_rx_handler[packet_type] = batadv_recv_unhandled_packet;
}
/** * batadv_skb_crc32() - calculate CRC32 of the whole packet and skip bytes in * the header * @skb: skb pointing to fragmented socket buffers * @payload_ptr: Pointer to position inside the head buffer of the skb * marking the start of the data to be CRC'ed * * payload_ptr must always point to an address in the skb head buffer and not to * a fragment. * * Return: big endian crc32c of the checksummed data
*/
__be32 batadv_skb_crc32(struct sk_buff *skb, u8 *payload_ptr)
{
u32 crc = 0; unsignedint from; unsignedint to = skb->len; struct skb_seq_state st; const u8 *data; unsignedint len; unsignedint consumed = 0;
/** * batadv_get_vid() - extract the VLAN identifier from skb if any * @skb: the buffer containing the packet * @header_len: length of the batman header preceding the ethernet header * * Return: VID with the BATADV_VLAN_HAS_TAG flag when the packet embedded in the * skb is vlan tagged. Otherwise BATADV_NO_FLAGS.
*/ unsignedshort batadv_get_vid(struct sk_buff *skb, size_t header_len)
{ struct ethhdr *ethhdr = (struct ethhdr *)(skb->data + header_len); struct vlan_ethhdr *vhdr; unsignedshort vid;
if (ethhdr->h_proto != htons(ETH_P_8021Q)) return BATADV_NO_FLAGS;
if (!pskb_may_pull(skb, header_len + VLAN_ETH_HLEN)) return BATADV_NO_FLAGS;
/* VID 0 is only used to indicate "priority tag" frames which only * contain priority information and no VID.
*/ if (vid == 0) return BATADV_NO_FLAGS;
vid |= BATADV_VLAN_HAS_TAG;
return vid;
}
/** * batadv_vlan_ap_isola_get() - return AP isolation status for the given vlan * @bat_priv: the bat priv with all the mesh interface information * @vid: the VLAN identifier for which the AP isolation attributed as to be * looked up * * Return: true if AP isolation is on for the VLAN identified by vid, false * otherwise
*/ bool batadv_vlan_ap_isola_get(struct batadv_priv *bat_priv, unsignedshort vid)
{ bool ap_isolation_enabled = false; struct batadv_meshif_vlan *vlan;
/* if the AP isolation is requested on a VLAN, then check for its * setting in the proper VLAN private data structure
*/
vlan = batadv_meshif_vlan_get(bat_priv, vid); if (vlan) {
ap_isolation_enabled = atomic_read(&vlan->ap_isolation);
batadv_meshif_vlan_put(vlan);
}
return ap_isolation_enabled;
}
/** * batadv_throw_uevent() - Send an uevent with batman-adv specific env data * @bat_priv: the bat priv with all the mesh interface information * @type: subsystem type of event. Stored in uevent's BATTYPE * @action: action type of event. Stored in uevent's BATACTION * @data: string with additional information to the event (ignored for * BATADV_UEV_DEL). Stored in uevent's BATDATA * * Return: 0 on success or negative error number in case of failure
*/ int batadv_throw_uevent(struct batadv_priv *bat_priv, enum batadv_uev_type type, enum batadv_uev_action action, constchar *data)
{ int ret = -ENOMEM; struct kobject *bat_kobj; char *uevent_env[4] = { NULL, NULL, NULL, NULL };
bat_kobj = &bat_priv->mesh_iface->dev.kobj;
uevent_env[0] = kasprintf(GFP_ATOMIC, "%s%s", BATADV_UEV_TYPE_VAR,
batadv_uev_type_str[type]); if (!uevent_env[0]) goto report_error;
uevent_env[1] = kasprintf(GFP_ATOMIC, "%s%s", BATADV_UEV_ACTION_VAR,
batadv_uev_action_str[action]); if (!uevent_env[1]) goto free_first_env;
/* If the event is DEL, ignore the data field */ if (action != BATADV_UEV_DEL) {
uevent_env[2] = kasprintf(GFP_ATOMIC, "%s%s", BATADV_UEV_DATA_VAR, data); if (!uevent_env[2]) goto free_second_env;
}
ret = kobject_uevent_env(bat_kobj, KOBJ_CHANGE, uevent_env);
kfree(uevent_env[2]);
free_second_env:
kfree(uevent_env[1]);
free_first_env:
kfree(uevent_env[0]);
if (ret)
report_error:
batadv_dbg(BATADV_DBG_BATMAN, bat_priv, "Impossible to send uevent for (%s,%s,%s) event (err: %d)\n",
batadv_uev_type_str[type],
batadv_uev_action_str[action],
(action == BATADV_UEV_DEL ? "NULL" : data), ret); return ret;
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.