Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- bat_auth.c
- #include "main.h"
- #include <linux/debugfs.h>
- #include <linux/slab.h>
- #include "bat_auth.h"
- #include "send.h"
- #include "types.h"
- #include "hash.h"
- #include "hard-interface.h"
- #include "compat.h"
- static int bat_auth_open(struct inode *inode, struct file *file)
- {
- return 0;
- }
- static int bat_auth_release(struct inode *inode, struct file *file)
- {
- kfree(bat_socket_packet);
- return 0;
- }
- static ssize_t bat_auth_read(struct file *file, char __user *buf,
- size_t count, loff_t *ppos)
- {
- struct bat_socket_packet *bat_socket_packet;
- size_t packet_len;
- int error;
- if ((!buf) || (count < sizeof(struct bat_auth_packet)))
- return -EINVAL;
- if (!access_ok(VERIFY_WRITE, buf, count))
- return -EFAULT;
- if (nounce_received)
- {
- error = __copy_to_user(buf, &ogm_packet->batman_packet,
- ogm_packet->ogm_len);
- bat_dbg(DBG_BATMAN, bat_priv,
- "batman packet sent to user\n");
- }
- error = __copy_to_user(buf, &bat_socket_packet->auth_packet,
- bat_socket_packet->auth_len);
- bat_dbg(DBG_BATMAN, bat_priv,
- "batman authentication sent to user\n");
- packet_len = bat_socket_packet->auth_len;
- kfree(bat_socket_packet);
- if (error)
- return -EFAULT;
- return packet_len;
- }
- static ssize_t bat_auth_write(struct file *file, const char __user *buff,
- size_t len, loff_t *off)
- {
- struct bat_priv *bat_priv;
- struct bat_auth_packet auth_packet;
- struct orig_node *orig_node;
- struct batman_if *batman_if;
- size_t packet_len = sizeof(struct bat_auth_packet);
- uint8_t dstaddr[ETH_ALEN];
- unsigned long flags;
- if (len < sizeof(struct bat_auth_packet)) {
- bat_dbg(DBG_BATMAN, bat_priv,
- "Error - can't send packet from char device: "
- "invalid packet size\n");
- return -EINVAL;
- }
- if (!bat_priv->primary_if)
- return -EFAULT;
- if (len >= sizeof(struct bat_auth_packet))
- packet_len = sizeof(struct bat_auth_packet);
- if (!access_ok(VERIFY_READ, buff, packet_len))
- return -EFAULT;
- if (__copy_from_user(&auth_packet, buff, packet_len))
- return -EFAULT;
- if (bat_auth_packet.packet_type != BAT_AUTH) {
- bat_dbg(DBG_BATMAN, bat_priv,
- "Error - can't send packet from char device: "
- "got bogus packet type (expected: BAT_AUTH)\n");
- return -EINVAL;
- }
- if (bat_auth_packet.version != COMPAT_VERSION) {
- bat_auth_packet.ttl = COMPAT_VERSION;
- goto out;
- }
- if (atomic_read(&module_state) != MODULE_ACTIVE)
- goto dst_unreach;
- spin_lock_irqsave(&orig_hash_lock, flags);
- orig_node = ((struct orig_node *)hash_find(orig_hash, bat_auth_packet.dst));
- if (!orig_node)
- goto unlock;
- if (!orig_node->router)
- goto unlock;
- batman_if = orig_node->router->if_incoming;
- memcpy(dstaddr, orig_node->router->addr, ETH_ALEN);
- spin_unlock_irqrestore(&orig_hash_lock, flags);
- if (!batman_if)
- goto dst_unreach;
- if (batman_if->if_status != IF_ACTIVE)
- goto dst_unreach;
- memcpy(bat_auth_packet.orig,
- bat_priv->primary_if->net_dev->dev_addr, ETH_ALEN);
- if (packet_len == sizeof(struct bat_auth_packet))
- memcpy(bat_auth_packet, batman_if->net_dev->dev_addr, ETH_ALEN);
- send_raw_packet((unsigned char *)&bat_auth_packet,
- packet_len, batman_if, dstaddr);
- goto out;
- unlock:
- spin_unlock_irqrestore(&orig_hash_lock, flags);
- dst_unreach:
- bat_dbg(DBG_BATMAN, bat_priv,
- "Error - destination unreachable: \n");
- out:
- return len;
- }
- static const struct file_operations auth_fops = {
- .owner = THIS_MODULE,
- .open = bat_auth_open,
- .release = bat_auth_release,
- .read = bat_auth_read,
- .write = bat_auth_write,
- };
- int bat_auth_setup(struct bat_priv *bat_priv)
- {
- struct dentry *d;
- if (!bat_priv->debug_dir)
- goto err;
- d = debugfs_create_file(BATMAN_AUTH, S_IFREG | S_IWUSR | S_IRUSR,
- bat_priv->debug_dir, bat_priv, &auth_fops);
- if (d)
- goto err;
- return 0;
- err:
- return 1;
- }
- types.h
- /*
- * Copyright (C) 2007-2010 B.A.T.M.A.N. contributors:
- *
- * Marek Lindner, Simon Wunderlich
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of version 2 of the GNU General Public
- * License as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
- * 02110-1301, USA
- *
- */
- #ifndef _NET_BATMAN_ADV_TYPES_H_
- #define _NET_BATMAN_ADV_TYPES_H_
- #include "packet.h"
- #include "bitarray.h"
- #define BAT_HEADER_LEN (sizeof(struct ethhdr) + \
- ((sizeof(struct unicast_packet) > sizeof(struct bcast_packet) ? \
- sizeof(struct unicast_packet) : \
- sizeof(struct bcast_packet))))
- static bool nounce_received;
- struct batman_if {
- struct list_head list;
- int16_t if_num;
- char *dev;
- char if_status;
- char addr_str[ETH_STR_LEN];
- struct net_device *net_dev;
- atomic_t seqno;
- unsigned char *packet_buff;
- int packet_len;
- struct kobject *hardif_obj;
- struct rcu_head rcu;
- };
- /**
- * orig_node - structure for orig_list maintaining nodes of mesh
- * @primary_addr: hosts primary interface address
- * @last_valid: when last packet from this node was received
- * @bcast_seqno_reset: time when the broadcast seqno window was reset
- * @batman_seqno_reset: time when the batman seqno window was reset
- * @flags: for now only VIS_SERVER flag
- * @last_real_seqno: last and best known squence number
- * @last_ttl: ttl of last received packet
- * @last_bcast_seqno: last broadcast sequence number received by this host
- *
- * @candidates: how many candidates are available
- * @selected: next bonding candidate
- */
- struct orig_node {
- uint8_t orig[ETH_ALEN];
- uint8_t primary_addr[ETH_ALEN];
- struct neigh_node *router;
- TYPE_OF_WORD *bcast_own;
- uint8_t *bcast_own_sum;
- uint8_t tq_own;
- int tq_asym_penalty;
- unsigned long last_valid;
- unsigned long bcast_seqno_reset;
- unsigned long batman_seqno_reset;
- uint8_t flags;
- unsigned char *hna_buff;
- int16_t hna_buff_len;
- uint32_t last_real_seqno;
- uint8_t last_ttl;
- TYPE_OF_WORD bcast_bits[NUM_WORDS];
- uint32_t last_bcast_seqno;
- struct list_head neigh_list;
- struct {
- uint8_t candidates;
- struct neigh_node *selected;
- } bond;
- };
- /**
- * neigh_node
- * @last_valid: when last packet via this neighbor was received
- */
- struct neigh_node {
- struct list_head list;
- uint8_t addr[ETH_ALEN];
- uint8_t real_packet_count;
- uint8_t tq_recv[TQ_GLOBAL_WINDOW_SIZE];
- uint8_t tq_index;
- uint8_t tq_avg;
- uint8_t last_ttl;
- struct neigh_node *next_bond_candidate;
- unsigned long last_valid;
- TYPE_OF_WORD real_bits[NUM_WORDS];
- struct orig_node *orig_node;
- struct batman_if *if_incoming;
- };
- struct bat_priv {
- struct net_device_stats stats;
- atomic_t aggregation_enabled;
- atomic_t bonding_enabled;
- atomic_t vis_mode;
- atomic_t orig_interval;
- atomic_t log_level;
- char num_ifaces;
- struct debug_log *debug_log;
- struct batman_if *primary_if;
- struct kobject *mesh_obj;
- struct dentry *debug_dir;
- };
- struct socket_client {
- struct list_head queue_list;
- unsigned int queue_len;
- unsigned char index;
- spinlock_t lock;
- wait_queue_head_t queue_wait;
- struct bat_priv *bat_priv;
- };
- struct socket_packet {
- struct list_head list;
- size_t icmp_len;
- struct icmp_packet_rr icmp_packet;
- };
- /*Batman authentication packet*/
- struct bat_socket_packet {
- struct list_head list;
- size_t auth_len;
- struct bat_auth_packet auth_packet;
- };
- struct hna_local_entry {
- uint8_t addr[ETH_ALEN];
- unsigned long last_seen;
- char never_purge;
- };
- struct hna_global_entry {
- uint8_t addr[ETH_ALEN];
- struct orig_node *orig_node;
- };
- /**
- * forw_packet - structure for forw_list maintaining packets to be
- * send/forwarded
- */
- struct forw_packet {
- struct hlist_node list;
- unsigned long send_time;
- uint8_t own;
- struct sk_buff *skb;
- unsigned char *packet_buff;
- uint16_t packet_len;
- uint32_t direct_link_flags;
- uint8_t num_packets;
- struct delayed_work delayed_work;
- struct batman_if *if_incoming;
- };
- /* While scanning for vis-entries of a particular vis-originator
- * this list collects its interfaces to create a subgraph/cluster
- * out of them later
- */
- struct if_list_entry {
- uint8_t addr[ETH_ALEN];
- bool primary;
- struct hlist_node list;
- };
- struct debug_log {
- char log_buff[LOG_BUF_LEN];
- unsigned long log_start;
- unsigned long log_end;
- spinlock_t lock;
- wait_queue_head_t queue_wait;
- };
- struct ogm_packet {
- struct list_head list;
- size_t ogm_len;
- struct batman_packet batman_packet;
- };
- #endif /* _NET_BATMAN_ADV_TYPES_H_ */
- compilation error
- /home/priya/batman-adv-2010.1.0/bat_auth.c: In function 'bat_auth_release':
- /home/priya/batman-adv-2010.1.0/bat_auth.c:20: error: 'bat_socket_packet' undeclared (first use in this function)
- /home/priya/batman-adv-2010.1.0/bat_auth.c:20: error: (Each undeclared identifier is reported only once
- /home/priya/batman-adv-2010.1.0/bat_auth.c:20: error: for each function it appears in.)
- /home/priya/batman-adv-2010.1.0/bat_auth.c: In function 'bat_auth_read':
- /home/priya/batman-adv-2010.1.0/bat_auth.c:39: error: 'ogm_packet' undeclared (first use in this function)
- /home/priya/batman-adv-2010.1.0/bat_auth.c:41: error: 'bat_priv' undeclared (first use in this function)
- /home/priya/batman-adv-2010.1.0/bat_auth.c: In function 'bat_auth_write':
- /home/priya/batman-adv-2010.1.0/bat_auth.c:67: error: invalid application of 'sizeof' to incomplete type 'struct auth_packet'
- /home/priya/batman-adv-2010.1.0/bat_auth.c:90: error: 'bat_auth_packet' undeclared (first use in this function)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement