diff options
Diffstat (limited to 'drivers/staging/batman-adv/soft-interface.c')
-rw-r--r-- | drivers/staging/batman-adv/soft-interface.c | 159 |
1 files changed, 77 insertions, 82 deletions
diff --git a/drivers/staging/batman-adv/soft-interface.c b/drivers/staging/batman-adv/soft-interface.c index 51c40b77c8d7..ef7860d53a5c 100644 --- a/drivers/staging/batman-adv/soft-interface.c +++ b/drivers/staging/batman-adv/soft-interface.c @@ -22,6 +22,7 @@ #include "main.h" #include "soft-interface.h" #include "hard-interface.h" +#include "routing.h" #include "send.h" #include "translation-table.h" #include "types.h" @@ -30,13 +31,12 @@ #include <linux/ethtool.h> #include <linux/etherdevice.h> -static uint16_t bcast_seqno = 1; /* give own bcast messages seq numbers to avoid +static uint32_t bcast_seqno = 1; /* give own bcast messages seq numbers to avoid * broadcast storms */ static int32_t skb_packets; static int32_t skb_bad_packets; unsigned char mainIfAddr[ETH_ALEN]; -static unsigned char mainIfAddr_default[ETH_ALEN]; static int bat_get_settings(struct net_device *dev, struct ethtool_cmd *cmd); static void bat_get_drvinfo(struct net_device *dev, struct ethtool_drvinfo *info); @@ -61,11 +61,6 @@ void set_main_if_addr(uint8_t *addr) memcpy(mainIfAddr, addr, ETH_ALEN); } -int main_if_was_up(void) -{ - return (memcmp(mainIfAddr, mainIfAddr_default, ETH_ALEN) != 0 ? 1 : 0); -} - int my_skb_push(struct sk_buff *skb, unsigned int len) { int result = 0; @@ -83,69 +78,25 @@ int my_skb_push(struct sk_buff *skb, unsigned int len) return 0; } -#ifdef HAVE_NET_DEVICE_OPS -static const struct net_device_ops bat_netdev_ops = { - .ndo_open = interface_open, - .ndo_stop = interface_release, - .ndo_get_stats = interface_stats, - .ndo_set_mac_address = interface_set_mac_addr, - .ndo_change_mtu = interface_change_mtu, - .ndo_start_xmit = interface_tx, - .ndo_validate_addr = eth_validate_addr -}; -#endif - -void interface_setup(struct net_device *dev) -{ - struct bat_priv *priv = netdev_priv(dev); - char dev_addr[ETH_ALEN]; - - ether_setup(dev); - -#ifdef HAVE_NET_DEVICE_OPS - dev->netdev_ops = &bat_netdev_ops; -#else - dev->open = interface_open; - dev->stop = interface_release; - dev->get_stats = interface_stats; - dev->set_mac_address = interface_set_mac_addr; - dev->change_mtu = interface_change_mtu; - dev->hard_start_xmit = interface_tx; -#endif - dev->destructor = free_netdev; - - dev->mtu = hardif_min_mtu(); - dev->hard_header_len = BAT_HEADER_LEN; /* reserve more space in the - * skbuff for our header */ - - /* generate random address */ - random_ether_addr(dev_addr); - memcpy(dev->dev_addr, dev_addr, ETH_ALEN); - - SET_ETHTOOL_OPS(dev, &bat_ethtool_ops); - - memset(priv, 0, sizeof(struct bat_priv)); -} - -int interface_open(struct net_device *dev) +static int interface_open(struct net_device *dev) { netif_start_queue(dev); return 0; } -int interface_release(struct net_device *dev) +static int interface_release(struct net_device *dev) { netif_stop_queue(dev); return 0; } -struct net_device_stats *interface_stats(struct net_device *dev) +static struct net_device_stats *interface_stats(struct net_device *dev) { struct bat_priv *priv = netdev_priv(dev); return &priv->stats; } -int interface_set_mac_addr(struct net_device *dev, void *p) +static int interface_set_mac_addr(struct net_device *dev, void *p) { struct sockaddr *addr = p; @@ -163,7 +114,7 @@ int interface_set_mac_addr(struct net_device *dev, void *p) return 0; } -int interface_change_mtu(struct net_device *dev, int new_mtu) +static int interface_change_mtu(struct net_device *dev, int new_mtu) { /* check ranges */ if ((new_mtu < 68) || (new_mtu > hardif_min_mtu())) @@ -179,6 +130,7 @@ int interface_tx(struct sk_buff *skb, struct net_device *dev) struct unicast_packet *unicast_packet; struct bcast_packet *bcast_packet; struct orig_node *orig_node; + struct neigh_node *router; struct ethhdr *ethhdr = (struct ethhdr *)skb->data; struct bat_priv *priv = netdev_priv(dev); struct batman_if *batman_if; @@ -205,6 +157,7 @@ int interface_tx(struct sk_buff *skb, struct net_device *dev) bcast_packet = (struct bcast_packet *)skb->data; bcast_packet->version = COMPAT_VERSION; + bcast_packet->ttl = TTL; /* batman packet type: broadcast */ bcast_packet->packet_type = BAT_BCAST; @@ -214,7 +167,7 @@ int interface_tx(struct sk_buff *skb, struct net_device *dev) memcpy(bcast_packet->orig, mainIfAddr, ETH_ALEN); /* set broadcast sequence number */ - bcast_packet->seqno = htons(bcast_seqno); + bcast_packet->seqno = htonl(bcast_seqno); /* broadcast packet. on success, increase seqno. */ if (add_bcast_packet_to_list(skb) == NETDEV_TX_OK) @@ -235,38 +188,36 @@ int interface_tx(struct sk_buff *skb, struct net_device *dev) if (!orig_node) orig_node = transtable_search(ethhdr->h_dest); - if ((orig_node) && - (orig_node->router)) { - struct neigh_node *router = orig_node->router; + router = find_router(orig_node, NULL); - if (my_skb_push(skb, sizeof(struct unicast_packet)) < 0) - goto unlock; + if (!router) + goto unlock; - unicast_packet = (struct unicast_packet *)skb->data; + /* don't lock while sending the packets ... we therefore + * copy the required data before sending */ - unicast_packet->version = COMPAT_VERSION; - /* batman packet type: unicast */ - unicast_packet->packet_type = BAT_UNICAST; - /* set unicast ttl */ - unicast_packet->ttl = TTL; - /* copy the destination for faster routing */ - memcpy(unicast_packet->dest, orig_node->orig, ETH_ALEN); + batman_if = router->if_incoming; + memcpy(dstaddr, router->addr, ETH_ALEN); - /* net_dev won't be available when not active */ - if (router->if_incoming->if_status != IF_ACTIVE) - goto unlock; + spin_unlock_irqrestore(&orig_hash_lock, flags); - /* don't lock while sending the packets ... we therefore - * copy the required data before sending */ + if (batman_if->if_status != IF_ACTIVE) + goto dropped; - batman_if = router->if_incoming; - memcpy(dstaddr, router->addr, ETH_ALEN); - spin_unlock_irqrestore(&orig_hash_lock, flags); + if (my_skb_push(skb, sizeof(struct unicast_packet)) < 0) + goto dropped; - send_skb_packet(skb, batman_if, dstaddr); - } else { - goto unlock; - } + unicast_packet = (struct unicast_packet *)skb->data; + + unicast_packet->version = COMPAT_VERSION; + /* batman packet type: unicast */ + unicast_packet->packet_type = BAT_UNICAST; + /* set unicast ttl */ + unicast_packet->ttl = TTL; + /* copy the destination for faster routing */ + memcpy(unicast_packet->dest, orig_node->orig, ETH_ALEN); + + send_skb_packet(skb, batman_if, dstaddr); } priv->stats.tx_packets++; @@ -315,6 +266,50 @@ void interface_rx(struct sk_buff *skb, int hdr_size) netif_rx(skb); } +#ifdef HAVE_NET_DEVICE_OPS +static const struct net_device_ops bat_netdev_ops = { + .ndo_open = interface_open, + .ndo_stop = interface_release, + .ndo_get_stats = interface_stats, + .ndo_set_mac_address = interface_set_mac_addr, + .ndo_change_mtu = interface_change_mtu, + .ndo_start_xmit = interface_tx, + .ndo_validate_addr = eth_validate_addr +}; +#endif + +void interface_setup(struct net_device *dev) +{ + struct bat_priv *priv = netdev_priv(dev); + char dev_addr[ETH_ALEN]; + + ether_setup(dev); + +#ifdef HAVE_NET_DEVICE_OPS + dev->netdev_ops = &bat_netdev_ops; +#else + dev->open = interface_open; + dev->stop = interface_release; + dev->get_stats = interface_stats; + dev->set_mac_address = interface_set_mac_addr; + dev->change_mtu = interface_change_mtu; + dev->hard_start_xmit = interface_tx; +#endif + dev->destructor = free_netdev; + + dev->mtu = hardif_min_mtu(); + dev->hard_header_len = BAT_HEADER_LEN; /* reserve more space in the + * skbuff for our header */ + + /* generate random address */ + random_ether_addr(dev_addr); + memcpy(dev->dev_addr, dev_addr, ETH_ALEN); + + SET_ETHTOOL_OPS(dev, &bat_ethtool_ops); + + memset(priv, 0, sizeof(struct bat_priv)); +} + /* ethtool */ static int bat_get_settings(struct net_device *dev, struct ethtool_cmd *cmd) { |