SHARE
TWEET

Untitled

a guest Jul 2nd, 2017 117 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. bat_auth.c
  2. #include "main.h"
  3. #include <linux/debugfs.h>
  4. #include <linux/slab.h>
  5. #include "bat_auth.h"
  6. #include "send.h"
  7. #include "types.h"
  8. #include "hash.h"
  9. #include "hard-interface.h"
  10.  
  11. #include "compat.h"
  12.  
  13. static int bat_auth_open(struct inode *inode, struct file *file)
  14. {
  15.  
  16.     return 0;
  17. }
  18.  
  19. static int bat_auth_release(struct inode *inode, struct file *file)
  20. {
  21.     kfree(bat_socket_packet);
  22.     return 0;
  23. }
  24.  
  25. static ssize_t bat_auth_read(struct file *file, char __user *buf,
  26.                    size_t count, loff_t *ppos)
  27. {
  28.     struct bat_socket_packet *bat_socket_packet;
  29.     size_t packet_len;
  30.     int error;
  31.  
  32.     if ((!buf) || (count < sizeof(struct bat_auth_packet)))
  33.         return -EINVAL;
  34.  
  35.     if (!access_ok(VERIFY_WRITE, buf, count))
  36.         return -EFAULT;
  37.  
  38.     if (nounce_received)
  39.     {
  40.         error = __copy_to_user(buf, &ogm_packet->batman_packet,
  41.                    ogm_packet->ogm_len);
  42.         bat_dbg(DBG_BATMAN, bat_priv,
  43.             "batman packet sent to user\n");
  44.     }
  45.  
  46.     error = __copy_to_user(buf, &bat_socket_packet->auth_packet,
  47.                    bat_socket_packet->auth_len);
  48.     bat_dbg(DBG_BATMAN, bat_priv,
  49.             "batman authentication sent to user\n");
  50.  
  51.     packet_len = bat_socket_packet->auth_len;
  52.     kfree(bat_socket_packet);
  53.  
  54.     if (error)
  55.         return -EFAULT;
  56.  
  57.     return packet_len;
  58. }
  59.  
  60. static ssize_t bat_auth_write(struct file *file, const char __user *buff,
  61.                 size_t len, loff_t *off)
  62. {
  63.    
  64.     struct bat_priv *bat_priv;
  65.     struct bat_auth_packet auth_packet;
  66.     struct orig_node *orig_node;
  67.     struct batman_if *batman_if;
  68.     size_t packet_len = sizeof(struct bat_auth_packet);
  69.     uint8_t dstaddr[ETH_ALEN];
  70.     unsigned long flags;
  71.  
  72.     if (len < sizeof(struct bat_auth_packet)) {
  73.         bat_dbg(DBG_BATMAN, bat_priv,
  74.             "Error - can't send packet from char device: "
  75.             "invalid packet size\n");
  76.         return -EINVAL;
  77.     }
  78.  
  79.     if (!bat_priv->primary_if)
  80.         return -EFAULT;
  81.  
  82.     if (len >= sizeof(struct bat_auth_packet))
  83.         packet_len = sizeof(struct bat_auth_packet);
  84.  
  85.     if (!access_ok(VERIFY_READ, buff, packet_len))
  86.         return -EFAULT;
  87.  
  88.     if (__copy_from_user(&auth_packet, buff, packet_len))
  89.         return -EFAULT;
  90.  
  91.     if (bat_auth_packet.packet_type != BAT_AUTH) {
  92.         bat_dbg(DBG_BATMAN, bat_priv,
  93.             "Error - can't send packet from char device: "
  94.             "got bogus packet type (expected: BAT_AUTH)\n");
  95.         return -EINVAL;
  96.     }
  97.  
  98.     if (bat_auth_packet.version != COMPAT_VERSION) {
  99.         bat_auth_packet.ttl = COMPAT_VERSION;
  100.         goto out;
  101.     }
  102.  
  103.     if (atomic_read(&module_state) != MODULE_ACTIVE)
  104.         goto dst_unreach;
  105.  
  106.     spin_lock_irqsave(&orig_hash_lock, flags);
  107.     orig_node = ((struct orig_node *)hash_find(orig_hash, bat_auth_packet.dst));
  108.  
  109.     if (!orig_node)
  110.         goto unlock;
  111.  
  112.     if (!orig_node->router)
  113.         goto unlock;
  114.  
  115.     batman_if = orig_node->router->if_incoming;
  116.     memcpy(dstaddr, orig_node->router->addr, ETH_ALEN);
  117.  
  118.     spin_unlock_irqrestore(&orig_hash_lock, flags);
  119.  
  120.     if (!batman_if)
  121.         goto dst_unreach;
  122.  
  123.     if (batman_if->if_status != IF_ACTIVE)
  124.         goto dst_unreach;
  125.  
  126.     memcpy(bat_auth_packet.orig,
  127.            bat_priv->primary_if->net_dev->dev_addr, ETH_ALEN);
  128.  
  129.     if (packet_len == sizeof(struct bat_auth_packet))
  130.         memcpy(bat_auth_packet, batman_if->net_dev->dev_addr, ETH_ALEN);
  131.  
  132.     send_raw_packet((unsigned char *)&bat_auth_packet,
  133.             packet_len, batman_if, dstaddr);
  134.  
  135.     goto out;
  136.  
  137. unlock:
  138.     spin_unlock_irqrestore(&orig_hash_lock, flags);
  139. dst_unreach:
  140.     bat_dbg(DBG_BATMAN, bat_priv,
  141.             "Error - destination unreachable: \n");
  142. out:
  143.     return len;
  144. }
  145.  
  146.  
  147. static const struct file_operations auth_fops = {
  148.     .owner = THIS_MODULE,
  149.     .open = bat_auth_open,
  150.     .release = bat_auth_release,
  151.     .read = bat_auth_read,
  152.     .write = bat_auth_write,
  153.    
  154. };
  155.  
  156. int bat_auth_setup(struct bat_priv *bat_priv)
  157. {
  158.     struct dentry *d;
  159.  
  160.     if (!bat_priv->debug_dir)
  161.         goto err;
  162.  
  163.     d = debugfs_create_file(BATMAN_AUTH, S_IFREG | S_IWUSR | S_IRUSR,
  164.                 bat_priv->debug_dir, bat_priv, &auth_fops);
  165.     if (d)
  166.         goto err;
  167.  
  168.     return 0;
  169.  
  170. err:
  171.     return 1;
  172. }
  173.  
  174. types.h
  175.  
  176. /*
  177.  * Copyright (C) 2007-2010 B.A.T.M.A.N. contributors:
  178.  *
  179.  * Marek Lindner, Simon Wunderlich
  180.  *
  181.  * This program is free software; you can redistribute it and/or
  182.  * modify it under the terms of version 2 of the GNU General Public
  183.  * License as published by the Free Software Foundation.
  184.  *
  185.  * This program is distributed in the hope that it will be useful, but
  186.  * WITHOUT ANY WARRANTY; without even the implied warranty of
  187.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  188.  * General Public License for more details.
  189.  *
  190.  * You should have received a copy of the GNU General Public License
  191.  * along with this program; if not, write to the Free Software
  192.  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
  193.  * 02110-1301, USA
  194.  *
  195.  */
  196.  
  197.  
  198.  
  199. #ifndef _NET_BATMAN_ADV_TYPES_H_
  200. #define _NET_BATMAN_ADV_TYPES_H_
  201.  
  202. #include "packet.h"
  203. #include "bitarray.h"
  204.  
  205. #define BAT_HEADER_LEN (sizeof(struct ethhdr) + \
  206.     ((sizeof(struct unicast_packet) > sizeof(struct bcast_packet) ? \
  207.      sizeof(struct unicast_packet) : \
  208.      sizeof(struct bcast_packet))))
  209.  
  210. static bool nounce_received;
  211.  
  212.  
  213. struct batman_if {
  214.     struct list_head list;
  215.     int16_t if_num;
  216.     char *dev;
  217.     char if_status;
  218.     char addr_str[ETH_STR_LEN];
  219.     struct net_device *net_dev;
  220.     atomic_t seqno;
  221.     unsigned char *packet_buff;
  222.     int packet_len;
  223.     struct kobject *hardif_obj;
  224.     struct rcu_head rcu;
  225.  
  226. };
  227.  
  228. /**
  229.   * orig_node - structure for orig_list maintaining nodes of mesh
  230.   * @primary_addr: hosts primary interface address
  231.   * @last_valid: when last packet from this node was received
  232.   * @bcast_seqno_reset: time when the broadcast seqno window was reset
  233.   * @batman_seqno_reset: time when the batman seqno window was reset
  234.   * @flags: for now only VIS_SERVER flag
  235.   * @last_real_seqno: last and best known squence number
  236.   * @last_ttl: ttl of last received packet
  237.   * @last_bcast_seqno: last broadcast sequence number received by this host
  238.   *
  239.   * @candidates: how many candidates are available
  240.   * @selected: next bonding candidate
  241.  */
  242. struct orig_node {
  243.     uint8_t orig[ETH_ALEN];
  244.     uint8_t primary_addr[ETH_ALEN];
  245.     struct neigh_node *router;
  246.     TYPE_OF_WORD *bcast_own;
  247.     uint8_t *bcast_own_sum;
  248.     uint8_t tq_own;
  249.     int tq_asym_penalty;
  250.     unsigned long last_valid;
  251.     unsigned long bcast_seqno_reset;
  252.     unsigned long batman_seqno_reset;
  253.     uint8_t  flags;
  254.     unsigned char *hna_buff;
  255.     int16_t hna_buff_len;
  256.     uint32_t last_real_seqno;
  257.     uint8_t last_ttl;
  258.     TYPE_OF_WORD bcast_bits[NUM_WORDS];
  259.     uint32_t last_bcast_seqno;
  260.     struct list_head neigh_list;
  261.     struct {
  262.         uint8_t candidates;
  263.         struct neigh_node *selected;
  264.     } bond;
  265. };
  266.  
  267. /**
  268.   * neigh_node
  269.   * @last_valid: when last packet via this neighbor was received
  270.  */
  271. struct neigh_node {
  272.     struct list_head list;
  273.     uint8_t addr[ETH_ALEN];
  274.     uint8_t real_packet_count;
  275.     uint8_t tq_recv[TQ_GLOBAL_WINDOW_SIZE];
  276.     uint8_t tq_index;
  277.     uint8_t tq_avg;
  278.     uint8_t last_ttl;
  279.     struct neigh_node *next_bond_candidate;
  280.     unsigned long last_valid;
  281.     TYPE_OF_WORD real_bits[NUM_WORDS];
  282.     struct orig_node *orig_node;
  283.     struct batman_if *if_incoming;
  284. };
  285.  
  286. struct bat_priv {
  287.     struct net_device_stats stats;
  288.     atomic_t aggregation_enabled;
  289.     atomic_t bonding_enabled;
  290.     atomic_t vis_mode;
  291.     atomic_t orig_interval;
  292.     atomic_t log_level;
  293.     char num_ifaces;
  294.     struct debug_log *debug_log;
  295.     struct batman_if *primary_if;
  296.     struct kobject *mesh_obj;
  297.     struct dentry *debug_dir;
  298. };
  299.  
  300. struct socket_client {
  301.     struct list_head queue_list;
  302.     unsigned int queue_len;
  303.     unsigned char index;
  304.     spinlock_t lock;
  305.     wait_queue_head_t queue_wait;
  306.     struct bat_priv *bat_priv;
  307. };
  308.  
  309. struct socket_packet {
  310.     struct list_head list;
  311.     size_t icmp_len;
  312.     struct icmp_packet_rr icmp_packet;
  313. };
  314.  
  315. /*Batman authentication packet*/
  316.  
  317. struct bat_socket_packet {
  318.     struct list_head list;
  319.     size_t auth_len;
  320.     struct bat_auth_packet auth_packet;
  321. };
  322.  
  323. struct hna_local_entry {
  324.     uint8_t addr[ETH_ALEN];
  325.     unsigned long last_seen;
  326.     char never_purge;
  327. };
  328.  
  329. struct hna_global_entry {
  330.     uint8_t addr[ETH_ALEN];
  331.     struct orig_node *orig_node;
  332. };
  333.  
  334. /**
  335.   * forw_packet - structure for forw_list maintaining packets to be
  336.   *               send/forwarded
  337.  */
  338. struct forw_packet {
  339.     struct hlist_node list;
  340.     unsigned long send_time;
  341.     uint8_t own;
  342.     struct sk_buff *skb;
  343.     unsigned char *packet_buff;
  344.     uint16_t packet_len;
  345.     uint32_t direct_link_flags;
  346.     uint8_t num_packets;
  347.     struct delayed_work delayed_work;
  348.     struct batman_if *if_incoming;
  349. };
  350.  
  351. /* While scanning for vis-entries of a particular vis-originator
  352.  * this list collects its interfaces to create a subgraph/cluster
  353.  * out of them later
  354.  */
  355. struct if_list_entry {
  356.     uint8_t addr[ETH_ALEN];
  357.     bool primary;
  358.     struct hlist_node list;
  359. };
  360.  
  361. struct debug_log {
  362.     char log_buff[LOG_BUF_LEN];
  363.     unsigned long log_start;
  364.     unsigned long log_end;
  365.     spinlock_t lock;
  366.     wait_queue_head_t queue_wait;
  367. };
  368.  
  369. struct ogm_packet {
  370.     struct list_head list;
  371.     size_t ogm_len;
  372.     struct batman_packet batman_packet;
  373. };
  374. #endif /* _NET_BATMAN_ADV_TYPES_H_ */
  375.  
  376.  
  377. compilation error
  378. /home/priya/batman-adv-2010.1.0/bat_auth.c: In function 'bat_auth_release':
  379. /home/priya/batman-adv-2010.1.0/bat_auth.c:20: error: 'bat_socket_packet' undeclared (first use in this function)
  380. /home/priya/batman-adv-2010.1.0/bat_auth.c:20: error: (Each undeclared identifier is reported only once
  381. /home/priya/batman-adv-2010.1.0/bat_auth.c:20: error: for each function it appears in.)
  382. /home/priya/batman-adv-2010.1.0/bat_auth.c: In function 'bat_auth_read':
  383. /home/priya/batman-adv-2010.1.0/bat_auth.c:39: error: 'ogm_packet' undeclared (first use in this function)
  384. /home/priya/batman-adv-2010.1.0/bat_auth.c:41: error: 'bat_priv' undeclared (first use in this function)
  385. /home/priya/batman-adv-2010.1.0/bat_auth.c: In function 'bat_auth_write':
  386. /home/priya/batman-adv-2010.1.0/bat_auth.c:67: error: invalid application of 'sizeof' to incomplete type 'struct auth_packet'
  387. /home/priya/batman-adv-2010.1.0/bat_auth.c:90: error: 'bat_auth_packet' undeclared (first use in this function)
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top