main.c (1f8dce4992d03fc15cfbaf67cd09f0d1648c4606) main.c (01d350d14712d1e8dbf2b00c82d2fc7c48d34e04)
1/* Copyright (C) 2007-2016 B.A.T.M.A.N. contributors:
2 *
3 * Marek Lindner, Simon Wunderlich
4 *
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of version 2 of the GNU General Public
7 * License as published by the Free Software Foundation.
8 *

--- 18 unchanged lines hidden (view full) ---

27#include <linux/if_vlan.h>
28#include <linux/init.h>
29#include <linux/ip.h>
30#include <linux/ipv6.h>
31#include <linux/kernel.h>
32#include <linux/kref.h>
33#include <linux/list.h>
34#include <linux/module.h>
1/* Copyright (C) 2007-2016 B.A.T.M.A.N. contributors:
2 *
3 * Marek Lindner, Simon Wunderlich
4 *
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of version 2 of the GNU General Public
7 * License as published by the Free Software Foundation.
8 *

--- 18 unchanged lines hidden (view full) ---

27#include <linux/if_vlan.h>
28#include <linux/init.h>
29#include <linux/ip.h>
30#include <linux/ipv6.h>
31#include <linux/kernel.h>
32#include <linux/kref.h>
33#include <linux/list.h>
34#include <linux/module.h>
35#include <linux/moduleparam.h>
36#include <linux/netdevice.h>
37#include <linux/rculist.h>
38#include <linux/rcupdate.h>
39#include <linux/seq_file.h>
40#include <linux/skbuff.h>
41#include <linux/spinlock.h>
42#include <linux/stddef.h>
43#include <linux/string.h>

--- 19 unchanged lines hidden (view full) ---

63#include "translation-table.h"
64
65/* List manipulations on hardif_list have to be rtnl_lock()'ed,
66 * list traversals just rcu-locked
67 */
68struct list_head batadv_hardif_list;
69static int (*batadv_rx_handler[256])(struct sk_buff *,
70 struct batadv_hard_iface *);
35#include <linux/netdevice.h>
36#include <linux/rculist.h>
37#include <linux/rcupdate.h>
38#include <linux/seq_file.h>
39#include <linux/skbuff.h>
40#include <linux/spinlock.h>
41#include <linux/stddef.h>
42#include <linux/string.h>

--- 19 unchanged lines hidden (view full) ---

62#include "translation-table.h"
63
64/* List manipulations on hardif_list have to be rtnl_lock()'ed,
65 * list traversals just rcu-locked
66 */
67struct list_head batadv_hardif_list;
68static int (*batadv_rx_handler[256])(struct sk_buff *,
69 struct batadv_hard_iface *);
71char batadv_routing_algo[20] = "BATMAN_IV";
72static struct hlist_head batadv_algo_list;
73
74unsigned char batadv_broadcast_addr[] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
75
76struct workqueue_struct *batadv_event_workqueue;
77
78static void batadv_recv_handler_init(void);
79
80static int __init batadv_init(void)
81{
82 INIT_LIST_HEAD(&batadv_hardif_list);
70
71unsigned char batadv_broadcast_addr[] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
72
73struct workqueue_struct *batadv_event_workqueue;
74
75static void batadv_recv_handler_init(void);
76
77static int __init batadv_init(void)
78{
79 INIT_LIST_HEAD(&batadv_hardif_list);
83 INIT_HLIST_HEAD(&batadv_algo_list);
80 batadv_algo_init();
84
85 batadv_recv_handler_init();
86
87 batadv_v_init();
88 batadv_iv_init();
89 batadv_nc_init();
90
91 batadv_event_workqueue = create_singlethread_workqueue("bat_events");

--- 438 unchanged lines hidden (view full) ---

530 return 0;
531}
532
533void batadv_recv_handler_unregister(u8 packet_type)
534{
535 batadv_rx_handler[packet_type] = batadv_recv_unhandled_packet;
536}
537
81
82 batadv_recv_handler_init();
83
84 batadv_v_init();
85 batadv_iv_init();
86 batadv_nc_init();
87
88 batadv_event_workqueue = create_singlethread_workqueue("bat_events");

--- 438 unchanged lines hidden (view full) ---

527 return 0;
528}
529
530void batadv_recv_handler_unregister(u8 packet_type)
531{
532 batadv_rx_handler[packet_type] = batadv_recv_unhandled_packet;
533}
534
538static struct batadv_algo_ops *batadv_algo_get(char *name)
539{
540 struct batadv_algo_ops *bat_algo_ops = NULL, *bat_algo_ops_tmp;
541
542 hlist_for_each_entry(bat_algo_ops_tmp, &batadv_algo_list, list) {
543 if (strcmp(bat_algo_ops_tmp->name, name) != 0)
544 continue;
545
546 bat_algo_ops = bat_algo_ops_tmp;
547 break;
548 }
549
550 return bat_algo_ops;
551}
552
553int batadv_algo_register(struct batadv_algo_ops *bat_algo_ops)
554{
555 struct batadv_algo_ops *bat_algo_ops_tmp;
556
557 bat_algo_ops_tmp = batadv_algo_get(bat_algo_ops->name);
558 if (bat_algo_ops_tmp) {
559 pr_info("Trying to register already registered routing algorithm: %s\n",
560 bat_algo_ops->name);
561 return -EEXIST;
562 }
563
564 /* all algorithms must implement all ops (for now) */
565 if (!bat_algo_ops->bat_iface_enable ||
566 !bat_algo_ops->bat_iface_disable ||
567 !bat_algo_ops->bat_iface_update_mac ||
568 !bat_algo_ops->bat_primary_iface_set ||
569 !bat_algo_ops->bat_neigh_cmp ||
570 !bat_algo_ops->bat_neigh_is_similar_or_better) {
571 pr_info("Routing algo '%s' does not implement required ops\n",
572 bat_algo_ops->name);
573 return -EINVAL;
574 }
575
576 INIT_HLIST_NODE(&bat_algo_ops->list);
577 hlist_add_head(&bat_algo_ops->list, &batadv_algo_list);
578
579 return 0;
580}
581
582int batadv_algo_select(struct batadv_priv *bat_priv, char *name)
583{
584 struct batadv_algo_ops *bat_algo_ops;
585
586 bat_algo_ops = batadv_algo_get(name);
587 if (!bat_algo_ops)
588 return -EINVAL;
589
590 bat_priv->bat_algo_ops = bat_algo_ops;
591
592 return 0;
593}
594
595int batadv_algo_seq_print_text(struct seq_file *seq, void *offset)
596{
597 struct batadv_algo_ops *bat_algo_ops;
598
599 seq_puts(seq, "Available routing algorithms:\n");
600
601 hlist_for_each_entry(bat_algo_ops, &batadv_algo_list, list) {
602 seq_printf(seq, " * %s\n", bat_algo_ops->name);
603 }
604
605 return 0;
606}
607
608/**
609 * batadv_skb_crc32 - calculate CRC32 of the whole packet and skip bytes in
610 * the header
611 * @skb: skb pointing to fragmented socket buffers
612 * @payload_ptr: Pointer to position inside the head buffer of the skb
613 * marking the start of the data to be CRC'ed
614 *
615 * payload_ptr must always point to an address in the skb head buffer and not to

--- 70 unchanged lines hidden (view full) ---

686 if (vlan) {
687 ap_isolation_enabled = atomic_read(&vlan->ap_isolation);
688 batadv_softif_vlan_put(vlan);
689 }
690
691 return ap_isolation_enabled;
692}
693
535/**
536 * batadv_skb_crc32 - calculate CRC32 of the whole packet and skip bytes in
537 * the header
538 * @skb: skb pointing to fragmented socket buffers
539 * @payload_ptr: Pointer to position inside the head buffer of the skb
540 * marking the start of the data to be CRC'ed
541 *
542 * payload_ptr must always point to an address in the skb head buffer and not to

--- 70 unchanged lines hidden (view full) ---

613 if (vlan) {
614 ap_isolation_enabled = atomic_read(&vlan->ap_isolation);
615 batadv_softif_vlan_put(vlan);
616 }
617
618 return ap_isolation_enabled;
619}
620
694static int batadv_param_set_ra(const char *val, const struct kernel_param *kp)
695{
696 struct batadv_algo_ops *bat_algo_ops;
697 char *algo_name = (char *)val;
698 size_t name_len = strlen(algo_name);
699
700 if (name_len > 0 && algo_name[name_len - 1] == '\n')
701 algo_name[name_len - 1] = '\0';
702
703 bat_algo_ops = batadv_algo_get(algo_name);
704 if (!bat_algo_ops) {
705 pr_err("Routing algorithm '%s' is not supported\n", algo_name);
706 return -EINVAL;
707 }
708
709 return param_set_copystring(algo_name, kp);
710}
711
712static const struct kernel_param_ops batadv_param_ops_ra = {
713 .set = batadv_param_set_ra,
714 .get = param_get_string,
715};
716
717static struct kparam_string batadv_param_string_ra = {
718 .maxlen = sizeof(batadv_routing_algo),
719 .string = batadv_routing_algo,
720};
721
722module_param_cb(routing_algo, &batadv_param_ops_ra, &batadv_param_string_ra,
723 0644);
724module_init(batadv_init);
725module_exit(batadv_exit);
726
727MODULE_LICENSE("GPL");
728
729MODULE_AUTHOR(BATADV_DRIVER_AUTHOR);
730MODULE_DESCRIPTION(BATADV_DRIVER_DESC);
731MODULE_SUPPORTED_DEVICE(BATADV_DRIVER_DEVICE);
732MODULE_VERSION(BATADV_SOURCE_VERSION);
621module_init(batadv_init);
622module_exit(batadv_exit);
623
624MODULE_LICENSE("GPL");
625
626MODULE_AUTHOR(BATADV_DRIVER_AUTHOR);
627MODULE_DESCRIPTION(BATADV_DRIVER_DESC);
628MODULE_SUPPORTED_DEVICE(BATADV_DRIVER_DEVICE);
629MODULE_VERSION(BATADV_SOURCE_VERSION);