|
From: Wang R. <wan...@gm...> - 2009-06-27 16:14:49
|
Hi all,
As I have said in my last mail (How to modify kaodv-ipenc.c to port
aodv-uu 0.9.5 to Linux kernel 2.6.26?), I tried to port aodv-uu-0.9.5 to
newer linux kernels, and I've done it. Using the patch I give below may make
aodv-uu-0.9.5 work on Linux Kernel >= 2.6.24 (I have tested it on 2.6.26 ~
2.6.28, but it should work on 2.6.24 kernel), and according to my test the
patch functions properly.
I have made the following modifications:
1. since one of nf_hook's parameter struct sk_buff **skb has changed
to struct sk_buff *skb, the corresponding code should be changed. These code
including struct sk_buff *ip_pkt_encapsulate(struct sk_buff *skb, __u32
dest) in lnx/kaodv-ipenc.c and kaodv_hook function in lnx/kaodv-mod.c. I've
virtually rewritten ip_pkt_encapsulate function, the result turn out to be
good except that if a packet's size is larger the MTU, the node won't
forward it.
2. changed netfilter hook names from NF_IP_XXX to NF_INET_XXX (e.g.
NF_IP_PRE_ROUTING => NF_INET_PRE_ROUTING)
3. the impl of proc fs have been rewritten since proc_net_create has
been deleted.
4. added net namespace support
5. added NF_INET_FORWARD hook. This hook will be activated when the
node is a gateway and the incoming packet is from the outer networks. By
doing this enables the gateway to search for a route requested by nodes
outside the ad hoc network to nodes which are not in the gateway's routing
table.
6. disabled hook NF_INET_POST_ROUTING. According to my experiments,
I found that if we update the timer of the route to dst node at
NF_INET_POST_ROUTING, the route won't invalidate when the route was
broken(intermediate nodes are down, or the dst node was down), if the source
node keeps sending packets to the dst node(e.g ping the dst node). As a
result, timer of a route is updated if and only if the node received a
packets from the dst nodes. It makes sense for the most of the times since
if a node received a packet from another node can indicate that the route
between these two nodes are OK.
I hope my work may help.
Wang Rui
Jun 28,2009
PS. My patch would work on kernels <2.6.24. I didn't do any work to enable
backward compatible.
diff -ur aodv-uu-0.9.5.orig/defs.h aodv-uu-0.9.5/defs.h
--- aodv-uu-0.9.5.orig/defs.h 2005-03-18 05:38:00.000000000 +0800
+++ aodv-uu-0.9.5/defs.h 2008-12-09 18:45:20.000000000 +0800
@@ -220,7 +220,7 @@
u_int8_t type;
u_int8_t length;
/* Type specific data follows here */
-} AODV_ext;
+}__attribute__((packed)) AODV_ext;
/* MACROS to access AODV extensions... */
#define AODV_EXT_HDR_SIZE sizeof(AODV_ext)
diff -ur aodv-uu-0.9.5.orig/lnx/kaodv-expl.c aodv-uu-0.9.5/lnx/kaodv-expl.c
--- aodv-uu-0.9.5.orig/lnx/kaodv-expl.c 2007-07-23 22:05:46.000000000 +0800
+++ aodv-uu-0.9.5/lnx/kaodv-expl.c 2009-03-03 14:38:10.000000000 +0800
@@ -267,15 +267,18 @@
return status;
}
-static int kaodv_expl_print(char *buf)
+/*
+ * proc filesystem def
+ */
+static int kaodv_expl_print(struct seq_file* m)
{
struct list_head *pos;
int len = 0;
read_lock_bh(&expl_lock);
- len += sprintf(buf, "# Total entries: %u\n", expl_len);
- len += sprintf(buf + len, "# %-15s %-15s %-5s %-5s Expires\n",
+ len += seq_printf(m, "# Total entries: %u\n", expl_len);
+ len += seq_printf(m, "# %-15s %-15s %-5s %-5s Expires\n",
"Addr", "Nhop", "Flags", "Iface");
list_for_each(pos, &expl_head) {
@@ -284,7 +287,7 @@
int num_flags = 0;
struct expl_entry *e = (struct expl_entry *)pos;
- dev = dev_get_by_index(e->ifindex);
+ dev = dev_get_by_index(&init_net,e->ifindex);
if (!dev)
continue;
@@ -307,7 +310,7 @@
flags[num_flags] = '\0';
- len += sprintf(buf + len, " %-15s %-15s %-5s %-5s %lu\n",
+ len += seq_printf(m, " %-15s %-15s %-5s %-5s %lu\n",
addr, nhop, flags, dev->name,
(e->expires - jiffies) * 1000 / HZ);
@@ -318,21 +321,28 @@
return len;
}
static int
-kaodv_expl_proc_info(char *buffer, char **start, off_t offset, int length)
+kaodv_expl_proc_info(struct seq_file* m,void* v)
+//char *buffer, char **start, off_t offset, int length)
{
- int len;
-
- len = kaodv_expl_print(buffer);
+ kaodv_expl_print(m);
+
+ return 0;
+}
- *start = buffer + offset;
- len -= offset;
- if (len > length)
- len = length;
- else if (len < 0)
- len = 0;
- return len;
+static int kaodv_expl_proc_open(struct inode* inode, struct file* file)
+{
+ return single_open(file,kaodv_expl_proc_info,NULL);
}
+static const struct file_operations kaodv_expl_proc_fops = {
+ .open = kaodv_expl_proc_open,
+ .read = seq_read,
+ .llseek = seq_lseek,
+ .release = single_release,
+ .owner = THIS_MODULE,
+};
+/* end proc def*/
+
int kaodv_expl_update(__u32 daddr, __u32 nhop, unsigned long time,
unsigned short flags, int ifindex)
{
@@ -384,7 +394,9 @@
void kaodv_expl_init(void)
{
- proc_net_create("kaodv_expl", 0, kaodv_expl_proc_info);
+// proc_net_create("kaodv_expl", 0, kaodv_expl_proc_info);
+ proc_create("kaodv_expl",0,init_net.proc_net,
+ &kaodv_expl_proc_fops);
expl_len = 0;
#ifdef EXPL_TIMER
@@ -395,5 +407,5 @@
void kaodv_expl_fini(void)
{
kaodv_expl_flush();
- proc_net_remove("kaodv_expl");
+ proc_net_remove(&init_net,"kaodv_expl");
}
diff -ur aodv-uu-0.9.5.orig/lnx/kaodv-ipenc.c
aodv-uu-0.9.5/lnx/kaodv-ipenc.c
--- aodv-uu-0.9.5.orig/lnx/kaodv-ipenc.c 2008-12-12
16:16:57.000000000 +0800
+++ aodv-uu-0.9.5/lnx/kaodv-ipenc.c 2009-03-03 14:38:10.000000000 +0800
@@ -20,6 +20,7 @@
*
****************************************************************************
*/
#include <net/ip.h>
+#include <linux/netfilter.h>
#include <linux/skbuff.h>
#include <linux/version.h>
@@ -43,43 +44,41 @@
struct sk_buff *ip_pkt_encapsulate(struct sk_buff *skb, __u32 dest)
{
-
-
struct min_ipenc_hdr *ipe;
- struct sk_buff *nskb;
struct iphdr *iph;
- /* Allocate new data space at head */
- nskb = skb_copy_expand(skb, skb_headroom(skb),
- skb_tailroom(skb) +
- sizeof(struct min_ipenc_hdr),
- GFP_ATOMIC);
-
- if (nskb == NULL) {
- printk("Could not allocate new skb\n");
- kfree_skb(skb);
- return NULL;
- }
-
- /* Set old owner */
- if (skb->sk != NULL)
- skb_set_owner_w(nskb, skb->sk);
#if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,22))
iph = skb->nh.iph;
#else
iph = (struct iphdr *)skb->network_header;
#endif
- skb_put(nskb, sizeof(struct min_ipenc_hdr));
+ if(!skb_make_writable(skb, (iph->ihl << 2))) {
+ printk("Could not make skb writable\n");
+ return NULL;
+ }
+
+ /* Allocate new data space at head */
+ if(skb_cow(skb,sizeof(struct min_ipenc_hdr)))
+ {
+ printk("Could not make enough head room\n");
+ return NULL;
+ }
+/*
+ if(skb_headroom(skb) < sizeof(struct min_ipenc_hdr)) {
+ if( pskb_expand_head(skb, sizeof(struct min_ipenc_hdr),
+ 0,GFP_ATOMIC) < 0) {
+ printk("Could not expand skb header\n");
+ kfree_skb(skb);
+ return NULL;
+ }
+ }
+*/
+ skb_push(skb, sizeof(struct min_ipenc_hdr));
/* Move the IP header */
- memcpy(nskb->data, skb->data, (iph->ihl << 2));
- /* Move the data */
- memcpy(nskb->data + (iph->ihl << 2) + sizeof(struct min_ipenc_hdr),
- skb->data + (iph->ihl << 2), skb->len - (iph->ihl << 2));
-
- kfree_skb(skb);
- skb = nskb;
+ memmove(skb->data, skb->data + sizeof(struct min_ipenc_hdr),
+ (iph->ihl << 2));
/* Update pointers */
#if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,22))
@@ -124,18 +123,30 @@
struct iphdr *iph = (struct iphdr *)skb->network_header;
#endif
+ if(!skb_make_writable(skb,(iph->ihl << 2))) {
+ printk("Could not make skb writable\n");
+ return NULL;
+ }
+
ipe = (struct min_ipenc_hdr *)((char *)iph + (iph->ihl << 2));
iph->protocol = ipe->protocol;
iph->daddr = ipe->daddr;
+ /*Shift the ip header to the right, overwriting the encap header*/
+ memmove(skb->data + sizeof(struct min_ipenc_hdr),skb->data,
+ (iph->ihl << 2));
+ skb_pull(skb,sizeof(struct min_ipenc_hdr));
+
/* Shift the data to the left, overwriting the encap header */
- memmove(skb->data + (iph->ihl << 2),
+ /*
+ memmove(skb->data + (iph->ihl << 2),
skb->data + (iph->ihl << 2) + sizeof(struct min_ipenc_hdr),
skb->len - (iph->ihl << 2) - sizeof(struct min_ipenc_hdr));
skb_trim(skb, skb->len - sizeof(struct min_ipenc_hdr));
-
+ */
+
#if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,22))
skb->nh.iph = iph = (struct iphdr *)skb->data;
#else
diff -ur aodv-uu-0.9.5.orig/lnx/kaodv-mod.c aodv-uu-0.9.5/lnx/kaodv-mod.c
--- aodv-uu-0.9.5.orig/lnx/kaodv-mod.c 2007-07-23 22:05:46.000000000 +0800
+++ aodv-uu-0.9.5/lnx/kaodv-mod.c 2009-03-17 21:02:33.000000000 +0800
@@ -41,6 +41,7 @@
#include <linux/tcp.h>
#include <net/tcp.h>
#include <net/route.h>
+#include <net/net_namespace.h>
#include "kaodv-mod.h"
#include "kaodv-expl.h"
@@ -86,7 +87,7 @@
if (res < 0)
return;
- if (hooknum == NF_IP_PRE_ROUTING)
+ if (hooknum == NF_INET_PRE_ROUTING)
kaodv_netlink_send_rt_update_msg(PKT_INBOUND, iph->saddr,
iph->daddr, dev->ifindex);
else if (iph->daddr != INADDR_BROADCAST && iph->daddr !=
bcaddr.s_addr)
@@ -116,7 +117,7 @@
}
static unsigned int kaodv_hook(unsigned int hooknum,
- struct sk_buff **skb,
+ struct sk_buff *skb,
const struct net_device *in,
const struct net_device *out,
int (*okfn) (struct sk_buff *))
@@ -124,7 +125,7 @@
#if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,22))
struct iphdr *iph = (*skb)->nh.iph;
#else
- struct iphdr *iph = (struct iphdr *)((*skb)->network_header);
+ struct iphdr *iph = (struct iphdr *)((skb)->network_header);
#endif
struct expl_entry e;
struct in_addr ifaddr, bcaddr;
@@ -137,6 +138,19 @@
if (iph == NULL)
return NF_ACCEPT;
+ /* Hook FORWARD only takecare of gateway packets */
+ if(hooknum == NF_INET_FORWARD)
+ {
+ //we are only handle forwarded packets in gateway mode
+ if(!is_gateway)
+ return NF_ACCEPT;
+ //we don't process packets from binded interface
+ if(!in || if_info_from_ifindex(NULL, NULL, in->ifindex) ==
0)
+ return NF_ACCEPT;
+ //we are only interested in packets heading to our ad-hoc
networks
+ if(!if_info_is_dst_local(iph))
+ return NF_ACCEPT;
+ }
/* We want AODV control messages to go through directly to the
* AODV socket.... */
if (iph && iph->protocol == IPPROTO_UDP) {
@@ -149,11 +163,11 @@
#ifdef CONFIG_QUAL_THRESHOLD
#if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0))
- qual = (int)(*skb)->__unused;
+ qual = (int)(skb)->__unused;
#elif (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0))
- qual = (*skb)->iwq.qual;
+ qual = (skb)->iwq.qual;
#endif
- if (qual_th && hooknum == NF_IP_PRE_ROUTING) {
+ if (qual_th && hooknum == NF_INET_PRE_ROUTING) {
if (qual && qual < qual_th) {
pkts_dropped++;
@@ -161,14 +175,14 @@
}
}
#endif /* CONFIG_QUAL_THRESHOLD */
- if (hooknum == NF_IP_PRE_ROUTING && in)
+ if (hooknum == NF_INET_PRE_ROUTING && in)
kaodv_update_route_timeouts(hooknum, in,
iph);
return NF_ACCEPT;
}
}
- if (hooknum == NF_IP_PRE_ROUTING)
+ if (hooknum == NF_INET_PRE_ROUTING)
res = if_info_from_ifindex(&ifaddr, &bcaddr, in->ifindex);
else
res = if_info_from_ifindex(&ifaddr, &bcaddr, out->ifindex);
@@ -186,17 +200,17 @@
/* Check which hook the packet is on... */
switch (hooknum) {
- case NF_IP_PRE_ROUTING:
+ case NF_INET_PRE_ROUTING:
kaodv_update_route_timeouts(hooknum, in, iph);
/* If we are a gateway maybe we need to decapsulate? */
if (is_gateway && iph->protocol == IPPROTO_MIPE &&
iph->daddr == ifaddr.s_addr) {
- ip_pkt_decapsulate(*skb);
+ ip_pkt_decapsulate(skb);
#if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,22))
- iph = (*skb)->nh.iph;
+ iph = (skb)->nh.iph;
#else
- iph = (struct iphdr *)((*skb)->network_header);
+ iph = (struct iphdr *)((skb)->network_header);
#endif
return NF_ACCEPT;
}
@@ -219,12 +233,13 @@
kaodv_netlink_send_rt_msg(KAODVM_REPAIR, iph->saddr,
iph->daddr);
- kaodv_queue_enqueue_packet(*skb, okfn);
+ kaodv_queue_enqueue_packet(skb, okfn);
return NF_STOLEN;
}
break;
- case NF_IP_LOCAL_OUT:
+ case NF_INET_FORWARD:
+ case NF_INET_LOCAL_OUT:
if (!kaodv_expl_get(iph->daddr, &e) ||
(e.flags & KAODV_RT_REPAIR)) {
@@ -234,7 +249,7 @@
0,
iph->daddr);
- kaodv_queue_enqueue_packet(*skb, okfn);
+ kaodv_queue_enqueue_packet(skb, okfn);
return NF_STOLEN;
@@ -248,12 +263,12 @@
that needs to be fix... */
if (iph->protocol == IPPROTO_TCP) {
- if ((*skb)->sk) {
+ if ((skb)->sk) {
struct tcp_sock *tp =
tcp_sk((*skb)->sk);
if (tp->mss_cache > 1452) {
tp->rx_opt.user_mss = 1452;
tp->rx_opt.mss_clamp = 1452;
- tcp_sync_mss((*skb)->sk,
1452);
+ tcp_sync_mss((skb)->sk,
1452);
}
}
}
@@ -262,9 +277,9 @@
* dest entry is refreshed */
kaodv_update_route_timeouts(hooknum, out, iph);
- *skb = ip_pkt_encapsulate(*skb, e.nhop);
+ ip_pkt_encapsulate(skb, e.nhop);
- if (!(*skb))
+ if (!(skb))
return NF_STOLEN;
#if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,18))
@@ -274,30 +289,39 @@
#endif
}
break;
- case NF_IP_POST_ROUTING:
- kaodv_update_route_timeouts(hooknum, out, iph);
+ case NF_INET_POST_ROUTING:
+ // kaodv_update_route_timeouts(hooknum, out, iph);
+ break;
}
return NF_ACCEPT;
}
-int kaodv_proc_info(char *buffer, char **start, off_t offset, int length)
+/*
+ * proc filesystem
+ */
+//int kaodv_proc_info(char *buffer, char **start, off_t offset, int length)
+static int kaodv_proc_show(struct seq_file* m, void* v)
{
- int len;
+ seq_printf(m,//buffer,
+ "qual threshold=%d\npkts dropped=%lu\nlast
qual=%d\ngateway_mode=%d\n",
+ qual_th, pkts_dropped, qual, is_gateway);
+
+ return 0;
+}
- len =
- sprintf(buffer,
- "qual threshold=%d\npkts dropped=%lu\nlast
qual=%d\ngateway_mode=%d\n",
- qual_th, pkts_dropped, qual, is_gateway);
-
- *start = buffer + offset;
- len -= offset;
- if (len > length)
- len = length;
- else if (len < 0)
- len = 0;
- return len;
+static int kaodv_proc_open(struct inode* inode, struct file* file)
+{
+ return single_open(file,kaodv_proc_show,NULL);
}
+static const struct file_operations kaodv_proc_fops = {
+ .open = kaodv_proc_open,
+ .read = seq_read,
+ .llseek = seq_lseek,
+ .release = single_release,
+ .owner = THIS_MODULE,
+};
+/* end proc def*/
/*
* Called when the module is inserted in the kernel.
*/
@@ -323,7 +347,7 @@
.owner = THIS_MODULE,
#endif
.pf = PF_INET,
- .hooknum = NF_IP_PRE_ROUTING,
+ .hooknum = NF_INET_PRE_ROUTING,
.priority = NF_IP_PRI_FIRST,
},
{
@@ -332,7 +356,7 @@
.owner = THIS_MODULE,
#endif
.pf = PF_INET,
- .hooknum = NF_IP_LOCAL_OUT,
+ .hooknum = NF_INET_FORWARD,
.priority = NF_IP_PRI_FILTER,
},
{
@@ -341,7 +365,16 @@
.owner = THIS_MODULE,
#endif
.pf = PF_INET,
- .hooknum = NF_IP_POST_ROUTING,
+ .hooknum = NF_INET_LOCAL_OUT,
+ .priority = NF_IP_PRI_FILTER,
+ },
+ {
+ .hook = kaodv_hook,
+#ifdef KERNEL26
+ .owner = THIS_MODULE,
+#endif
+ .pf = PF_INET,
+ .hooknum = NF_INET_POST_ROUTING,
.priority = NF_IP_PRI_FILTER,
},
};
@@ -382,13 +415,18 @@
if (ret < 0)
goto cleanup_hook1;
+ ret = nf_register_hook(&kaodv_ops[3]);
+
+ if (ret < 0)
+ goto cleanup_hook2;
+
/* Prefetch network device info (ip, broadcast address, ifindex). */
for (i = 0; i < MAX_INTERFACES; i++) {
if (!ifname[i])
break;
- dev = dev_get_by_name(ifname[i]);
+ dev = dev_get_by_name(&init_net,ifname[i]);
if (!dev) {
printk("No device %s available, ignoring!\n",
ifname[i]);
@@ -399,12 +437,15 @@
dev_put(dev);
}
- proc_net_create("kaodv", 0, kaodv_proc_info);
+ //proc_net_create("kaodv", 0, kaodv_proc_info);
+ proc_create("kaodv", 0, init_net.proc_net,&kaodv_proc_fops);
KAODV_DEBUG("Module init OK");
return ret;
+cleanup_hook2:
+ nf_unregister_hook(&kaodv_ops[2]);
cleanup_hook1:
nf_unregister_hook(&kaodv_ops[1]);
cleanup_hook0:
@@ -429,7 +470,7 @@
for (i = 0; i < sizeof(kaodv_ops) / sizeof(struct nf_hook_ops); i++)
nf_unregister_hook(&kaodv_ops[i]);
- proc_net_remove("kaodv");
+ proc_net_remove(&init_net,"kaodv");
kaodv_queue_fini();
kaodv_expl_fini();
diff -ur aodv-uu-0.9.5.orig/lnx/kaodv-mod.h aodv-uu-0.9.5/lnx/kaodv-mod.h
--- aodv-uu-0.9.5.orig/lnx/kaodv-mod.h 2006-09-21 01:58:38.000000000 +0800
+++ aodv-uu-0.9.5/lnx/kaodv-mod.h 2009-03-03 15:10:39.000000000 +0800
@@ -11,6 +11,7 @@
struct list_head l;
struct in_addr if_addr;
struct in_addr bc_addr;
+ struct in_addr mask_addr;
struct net_device *dev;
};
@@ -47,6 +48,7 @@
if (ifa) {
ifi->if_addr.s_addr = ifa->ifa_address;
ifi->bc_addr.s_addr = ifa->ifa_broadcast;
+ ifi->mask_addr.s_addr = ifa->ifa_mask;
}
in_dev_put(indev);
}
@@ -72,6 +74,27 @@
write_unlock(&ifilock);
}
+static inline int if_info_is_dst_local(const struct iphdr *iph)
+{
+ struct list_head *pos;
+ int res = 0;
+
+ if(!iph)
+ return res;
+
+ read_lock(&ifilock);
+ list_for_each(pos, &ifihead) {
+ struct if_info *ifi = (struct if_info *)pos;
+ if((iph->daddr & ifi->mask_addr.s_addr) ==
+ (ifi->if_addr.s_addr &
ifi->mask_addr.s_addr))
+ res = 1;
+ break;
+ }
+ read_unlock(&ifilock);
+
+ return res;
+}
+
static inline int if_info_from_ifindex(struct in_addr *ifa, struct in_addr
*bc,
int ifindex)
{
diff -ur aodv-uu-0.9.5.orig/lnx/kaodv-netlink.c
aodv-uu-0.9.5/lnx/kaodv-netlink.c
--- aodv-uu-0.9.5.orig/lnx/kaodv-netlink.c 2007-07-23
22:05:46.000000000 +0800
+++ aodv-uu-0.9.5/lnx/kaodv-netlink.c 2009-03-03 14:38:10.000000000 +0800
@@ -248,7 +248,7 @@
#define RCV_SKB_FAIL(err) do { netlink_ack(skb, nlh, (err)); return; }
while (0)
-static inline void kaodv_netlink_rcv_skb(struct sk_buff *skb)
+static inline void __kaodv_netlink_rcv_skb(struct sk_buff *skb)
{
int status, type, pid, flags, nlmsglen, skblen;
struct nlmsghdr *nlh;
@@ -313,22 +313,24 @@
return;
}
-static void kaodv_netlink_rcv_sk(struct sock *sk, int len)
+static void kaodv_netlink_rcv_sk(struct sk_buff *skb)
{
- do {
- struct sk_buff *skb;
+// do {
+// struct sk_buff *skb;
- if (down_trylock(&kaodvnl_sem))
- return;
+ if (down_trylock(&kaodvnl_sem))
+ return;
- while ((skb = skb_dequeue(&sk->sk_receive_queue)) != NULL) {
- kaodv_netlink_rcv_skb(skb);
- kfree_skb(skb);
- }
+// while ((skb = skb_dequeue(&sk->sk_receive_queue)) != NULL) {
+
+ __kaodv_netlink_rcv_skb(skb);
- up(&kaodvnl_sem);
+// kfree_skb(skb);
+// }
+
+ up(&kaodvnl_sem);
- } while (kaodvnl && kaodvnl->sk_receive_queue.qlen);
+// } while (kaodvnl && kaodvnl->sk_receive_queue.qlen);
return;
}
@@ -341,7 +343,7 @@
#elif (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,22))
kaodvnl = netlink_kernel_create(NETLINK_AODV, AODVGRP_MAX,
kaodv_netlink_rcv_sk, THIS_MODULE);
#else
- kaodvnl = netlink_kernel_create(NETLINK_AODV, AODVGRP_MAX,
kaodv_netlink_rcv_sk, NULL, THIS_MODULE);
+ kaodvnl = netlink_kernel_create(&init_net,NETLINK_AODV, AODVGRP_MAX,
kaodv_netlink_rcv_sk, NULL, THIS_MODULE);
#endif
if (kaodvnl == NULL) {
printk(KERN_ERR "kaodv_netlink: failed to create netlink
socket\n");
diff -ur aodv-uu-0.9.5.orig/lnx/kaodv-queue.c
aodv-uu-0.9.5/lnx/kaodv-queue.c
--- aodv-uu-0.9.5.orig/lnx/kaodv-queue.c 2007-07-23
22:05:46.000000000 +0800
+++ aodv-uu-0.9.5/lnx/kaodv-queue.c 2009-03-03 14:38:10.000000000 +0800
@@ -33,7 +33,7 @@
#include <net/sock.h>
#include <net/route.h>
#include <net/icmp.h>
-
+#include <net/net_namespace.h>
#include "kaodv-queue.h"
#include "kaodv-expl.h"
#include "kaodv-netlink.h"
@@ -253,7 +253,7 @@
#if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,18))
ip_route_me_harder(&entry->skb);
#else
- ip_route_me_harder(&entry->skb, RTN_LOCAL);
+ ip_route_me_harder(entry->skb, RTN_LOCAL);
#endif
pkts++;
@@ -265,28 +265,38 @@
}
return 0;
}
-
-static int kaodv_queue_get_info(char *buffer, char **start, off_t offset,
int length)
+/*
+ * proc filesystem
+ */
+static int kaodv_queue_proc_show(struct seq_file* m,void* v)
+//char *buffer, char **start, off_t offset, int length)
{
- int len;
-
read_lock_bh(&queue_lock);
-
- len = sprintf(buffer,
- "Queue length : %u\n"
- "Queue max. length : %u\n", queue_total,
queue_maxlen);
+
+ seq_printf( m,
+ "Queue length : %u\n"
+ "Queue max. length : %u\n",
+ queue_total, queue_maxlen);
read_unlock_bh(&queue_lock);
- *start = buffer + offset;
- len -= offset;
- if (len > length)
- len = length;
- else if (len < 0)
- len = 0;
- return len;
+ return 0;
+}
+
+static int kaodv_queue_proc_open(struct inode* inode, struct file* file)
+{
+ return single_open(file,kaodv_queue_proc_show,NULL);
}
+static const struct file_operations kaodv_queue_proc_fops = {
+ .open = kaodv_queue_proc_open,
+ .read = seq_read,
+ .llseek = seq_lseek,
+ .release = single_release,
+ .owner = THIS_MODULE,
+};
+/* end proc def*/
+
static int init_or_cleanup(int init)
{
int status = -ENOMEM;
@@ -297,7 +307,9 @@
queue_total = 0;
proc =
- proc_net_create(KAODV_QUEUE_PROC_FS_NAME, 0,
kaodv_queue_get_info);
+ //proc_net_create(KAODV_QUEUE_PROC_FS_NAME, 0,
kaodv_queue_get_info);
+ proc_create(KAODV_QUEUE_PROC_FS_NAME,0,init_net.proc_net,
+ &kaodv_queue_proc_fops);
if (proc)
proc->owner = THIS_MODULE;
else {
@@ -312,7 +324,7 @@
#endif
kaodv_queue_flush();
- proc_net_remove(KAODV_QUEUE_PROC_FS_NAME);
+ proc_net_remove(&init_net,KAODV_QUEUE_PROC_FS_NAME);
return status;
}
diff -ur aodv-uu-0.9.5.orig/main.c aodv-uu-0.9.5/main.c
--- aodv-uu-0.9.5.orig/main.c 2007-04-06 16:37:04.000000000 +0800
+++ aodv-uu-0.9.5/main.c 2008-12-03 10:39:52.000000000 +0800
@@ -136,22 +136,24 @@
char command[64];
if ((fd = open("/proc/sys/net/ipv4/ip_forward", O_WRONLY)) < 0)
- return -1;
+ return -1;
if (write(fd, &on, sizeof(char)) < 0)
- return -1;
- close(fd);
-
- if ((fd = open("/proc/sys/net/ipv4/route/max_delay", O_WRONLY)) < 0)
- return -1;
- if (write(fd, &off, sizeof(char)) < 0)
- return -1;
+ return -1;
close(fd);
+ if ((fd = open("/proc/sys/net/ipv4/route/max_delay", O_WRONLY)) > 0)
+ {
+ if (write(fd, &off, sizeof(char)) < 0)
+ return -1;
+ close(fd);
+ }
- if ((fd = open("/proc/sys/net/ipv4/route/min_delay", O_WRONLY)) < 0)
- return -1;
- if (write(fd, &off, sizeof(char)) < 0)
- return -1;
- close(fd);
+ if ((fd = open("/proc/sys/net/ipv4/route/min_delay", O_WRONLY)) > 0)
+ {
+ if (write(fd, &off, sizeof(char)) < 0)
+ return -1;
+
+ close(fd);
+ }
/* Disable ICMP redirects on all interfaces: */
@@ -178,7 +180,7 @@
}
memset(command, '\0', 64);
sprintf(command, "/proc/sys/net/ipv4/conf/all/send_redirects");
- if ((fd = open(command, O_WRONLY)) < 0)
+ if ((fd = open(command, O_WRONLY)) < 0)
return -1;
if (write(fd, &off, sizeof(char)) < 0)
return -1;
@@ -187,7 +189,7 @@
memset(command, '\0', 64);
sprintf(command, "/proc/sys/net/ipv4/conf/all/accept_redirects");
- if ((fd = open(command, O_WRONLY)) < 0)
+ if ((fd = open(command, O_WRONLY)) < 0)
return -1;
if (write(fd, &off, sizeof(char)) < 0)
return -1;
__________ Information from ESET NOD32 Antivirus, version of virus signature
database 4193 (20090626) __________
The message was checked by ESET NOD32 Antivirus.
http://www.eset.com
|