Lines 28-33
Link Here
|
28 |
#include <linux/udp.h> |
28 |
#include <linux/udp.h> |
29 |
#include <net/protocol.h> |
29 |
#include <net/protocol.h> |
30 |
|
30 |
|
|
|
31 |
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,24) |
32 |
#include <net/net_namespace.h> |
33 |
#endif |
34 |
|
31 |
#include "linux_os.h" |
35 |
#include "linux_os.h" |
32 |
|
36 |
|
33 |
#include "vpn_ioctl_linux.h" |
37 |
#include "vpn_ioctl_linux.h" |
Lines 48-54
Link Here
|
48 |
unsigned long rx_bytes; |
52 |
unsigned long rx_bytes; |
49 |
|
53 |
|
50 |
/*methods of the cipsec network device*/ |
54 |
/*methods of the cipsec network device*/ |
51 |
static int interceptor_init(struct net_device *); |
55 |
static void interceptor_init(struct net_device *); |
52 |
static struct net_device_stats *interceptor_stats(struct net_device *dev); |
56 |
static struct net_device_stats *interceptor_stats(struct net_device *dev); |
53 |
static int interceptor_ioctl(struct net_device *dev, struct ifreq *ifr, |
57 |
static int interceptor_ioctl(struct net_device *dev, struct ifreq *ifr, |
54 |
int cmd); |
58 |
int cmd); |
Lines 120-145
Link Here
|
120 |
.notifier_call = handle_netdev_event, |
124 |
.notifier_call = handle_netdev_event, |
121 |
}; |
125 |
}; |
122 |
|
126 |
|
|
|
127 |
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,29) |
128 |
static const struct net_device_ops interceptor_netdev_ops = { |
129 |
.ndo_start_xmit = interceptor_tx, |
130 |
.ndo_get_stats = interceptor_stats, |
131 |
.ndo_do_ioctl = interceptor_ioctl, |
132 |
}; |
133 |
static const struct net_device_ops replacement_netdev_ops = { |
134 |
.ndo_start_xmit = replacement_dev_xmit, |
135 |
.ndo_get_stats = interceptor_stats, |
136 |
.ndo_do_ioctl = interceptor_ioctl, |
137 |
}; |
138 |
#endif |
139 |
|
123 |
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,22) |
140 |
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,22) |
124 |
static int |
141 |
static void |
125 |
#else |
142 |
#else |
126 |
static int __init |
143 |
static void __init |
127 |
#endif |
144 |
#endif |
128 |
interceptor_init(struct net_device *dev) |
145 |
interceptor_init(struct net_device *dev) |
129 |
{ |
146 |
{ |
130 |
ether_setup(dev); |
147 |
ether_setup(dev); |
131 |
|
148 |
|
|
|
149 |
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,29) |
150 |
/* |
151 |
* The new netops have to be used. |
152 |
*/ |
153 |
dev->netdev_ops = &interceptor_netdev_ops; |
154 |
#else |
132 |
dev->hard_start_xmit = interceptor_tx; |
155 |
dev->hard_start_xmit = interceptor_tx; |
133 |
dev->get_stats = interceptor_stats; |
156 |
dev->get_stats = interceptor_stats; |
134 |
dev->do_ioctl = interceptor_ioctl; |
157 |
dev->do_ioctl = interceptor_ioctl; |
|
|
158 |
#endif |
135 |
|
159 |
|
136 |
dev->mtu = ETH_DATA_LEN-MTU_REDUCTION; |
160 |
dev->mtu = ETH_DATA_LEN-MTU_REDUCTION; |
137 |
kernel_memcpy(dev->dev_addr, interceptor_eth_addr,ETH_ALEN); |
161 |
kernel_memcpy(dev->dev_addr, interceptor_eth_addr,ETH_ALEN); |
138 |
dev->flags |= IFF_NOARP; |
162 |
dev->flags |= IFF_NOARP; |
139 |
dev->flags &= ~(IFF_BROADCAST | IFF_MULTICAST); |
163 |
dev->flags &= ~(IFF_BROADCAST | IFF_MULTICAST); |
140 |
kernel_memset(dev->broadcast, 0xFF, ETH_ALEN); |
164 |
kernel_memset(dev->broadcast, 0xFF, ETH_ALEN); |
141 |
|
|
|
142 |
return 0; |
143 |
} |
165 |
} |
144 |
|
166 |
|
145 |
static struct net_device_stats * |
167 |
static struct net_device_stats * |
Lines 268-275
Link Here
|
268 |
Bindings[i].original_mtu = dev->mtu; |
290 |
Bindings[i].original_mtu = dev->mtu; |
269 |
|
291 |
|
270 |
/*replace the original send function with our send function */ |
292 |
/*replace the original send function with our send function */ |
|
|
293 |
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,29) |
294 |
Bindings[i].Inject_ops = dev->netdev_ops; |
295 |
dev->netdev_ops = &replacement_netdev_ops; |
296 |
#else |
271 |
Bindings[i].InjectSend = dev->hard_start_xmit; |
297 |
Bindings[i].InjectSend = dev->hard_start_xmit; |
272 |
dev->hard_start_xmit = replacement_dev_xmit; |
298 |
dev->hard_start_xmit = replacement_dev_xmit; |
|
|
299 |
#endif |
273 |
|
300 |
|
274 |
/*copy in the ip packet handler function and packet type struct */ |
301 |
/*copy in the ip packet handler function and packet type struct */ |
275 |
Bindings[i].InjectReceive = original_ip_handler.orig_handler_func; |
302 |
Bindings[i].InjectReceive = original_ip_handler.orig_handler_func; |
Lines 291-297
Link Here
|
291 |
if (b) |
318 |
if (b) |
292 |
{ |
319 |
{ |
293 |
rc = 0; |
320 |
rc = 0; |
|
|
321 |
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,29) |
322 |
dev->netdev_ops = b->Inject_ops; |
323 |
dev->mtu = b->original_mtu; |
324 |
#else |
294 |
dev->hard_start_xmit = b->InjectSend; |
325 |
dev->hard_start_xmit = b->InjectSend; |
|
|
326 |
#endif |
295 |
kernel_memset(b, 0, sizeof(BINDING)); |
327 |
kernel_memset(b, 0, sizeof(BINDING)); |
296 |
} |
328 |
} |
297 |
else |
329 |
else |
Lines 637-655
Link Here
|
637 |
|
669 |
|
638 |
reset_inject_status(&pBinding->recv_stat); |
670 |
reset_inject_status(&pBinding->recv_stat); |
639 |
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,22) |
671 |
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,22) |
640 |
if (skb->mac_header) |
672 |
/* 2.6.22 added an inline function for 32-/64-bit usage here, so use it. |
|
|
673 |
*/ |
674 |
if (skb_mac_header_was_set(skb)) |
641 |
#else |
675 |
#else |
642 |
if (skb->mac.raw) |
676 |
if (skb->mac.raw) |
643 |
#endif |
677 |
#endif |
644 |
{ |
678 |
{ |
645 |
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,22) |
679 |
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,22) |
646 |
hard_header_len = skb->data - skb->mac_header; |
680 |
/* 2.6.22 added an inline function for 32-/64-bit usage here, so use it. |
|
|
681 |
*/ |
682 |
hard_header_len = skb->data - skb_mac_header(skb); |
647 |
#else |
683 |
#else |
648 |
hard_header_len = skb->data - skb->mac.raw; |
684 |
hard_header_len = skb->data - skb->mac.raw; |
649 |
#endif |
685 |
#endif |
650 |
if ((hard_header_len < 0) || (hard_header_len > skb_headroom(skb))) |
686 |
if ((hard_header_len < 0) || (hard_header_len > skb_headroom(skb))) |
651 |
{ |
687 |
{ |
652 |
printk(KERN_DEBUG "bad hh len %d\n", hard_header_len); |
688 |
printk(KERN_DEBUG "bad hh len %d, mac: %p, data: %p, head: %p\n", |
|
|
689 |
hard_header_len, |
690 |
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,22) |
691 |
skb->mac_header, /* actualy ptr in 32-bit */ |
692 |
#else |
693 |
skb->mac.raw, |
694 |
#endif |
695 |
skb->data, |
696 |
skb->head); |
653 |
hard_header_len = 0; |
697 |
hard_header_len = 0; |
654 |
} |
698 |
} |
655 |
} |
699 |
} |
Lines 664-670
Link Here
|
664 |
{ |
708 |
{ |
665 |
case ETH_HLEN: |
709 |
case ETH_HLEN: |
666 |
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,22) |
710 |
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,22) |
667 |
CniNewFragment(ETH_HLEN, skb->mac_header, &MacHdr, CNI_USE_BUFFER); |
711 |
/* 2.6.22 added an inline function for 32-/64-bit usage here, so use it. |
|
|
712 |
*/ |
713 |
CniNewFragment(ETH_HLEN, skb_mac_header(skb), &MacHdr, CNI_USE_BUFFER); |
668 |
#else |
714 |
#else |
669 |
CniNewFragment(ETH_HLEN, skb->mac.raw, &MacHdr, CNI_USE_BUFFER); |
715 |
CniNewFragment(ETH_HLEN, skb->mac.raw, &MacHdr, CNI_USE_BUFFER); |
670 |
#endif |
716 |
#endif |
Lines 718-725
Link Here
|
718 |
|
764 |
|
719 |
break; |
765 |
break; |
720 |
case CNI_DISCARD: |
766 |
case CNI_DISCARD: |
721 |
dev_kfree_skb(skb); |
767 |
/* patch found on ubuntuforums.org, written by aranoyas */ |
722 |
rx_dropped++; |
768 |
/* override local LAN access */ |
|
|
769 |
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,14) |
770 |
rc2 = original_ip_handler.orig_handler_func(skb, dev, type, dev); |
771 |
#else |
772 |
rc2 = original_ip_handler.orig_handler_func(skb, dev, type); |
773 |
#endif |
723 |
break; |
774 |
break; |
724 |
default: |
775 |
default: |
725 |
printk(KERN_DEBUG "RECV: Unhandled case in %s rc was %x\n", |
776 |
printk(KERN_DEBUG "RECV: Unhandled case in %s rc was %x\n", |
Lines 784-790
Link Here
|
784 |
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,22) |
835 |
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,22) |
785 |
hard_header_len = skb->network_header - skb->data; |
836 |
hard_header_len = skb->network_header - skb->data; |
786 |
#else |
837 |
#else |
787 |
hard_header_len = skb->nh.raw - skb->data; |
838 |
/* 2.6.22 added an inline function for 32-/64-bit usage here, so use it. |
|
|
839 |
*/ |
840 |
hard_header_len = skb_network_header(skb) - skb->data; |
788 |
#endif |
841 |
#endif |
789 |
pBinding->send_real_hh_len = hard_header_len; |
842 |
pBinding->send_real_hh_len = hard_header_len; |
790 |
switch (hard_header_len) |
843 |
switch (hard_header_len) |
Lines 840-851
Link Here
|
840 |
/* packet dropped */ |
893 |
/* packet dropped */ |
841 |
else |
894 |
else |
842 |
{ |
895 |
{ |
843 |
dev_kfree_skb(skb); |
896 |
/* patch found on ubuntuforums.org, originally written by aranoyas */ |
844 |
tx_dropped++; |
897 |
/* override local LAN access */ |
|
|
898 |
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,29) |
899 |
rc2 = pBinding->Inject_ops->ndo_start_xmit(skb, dev); |
900 |
#else |
901 |
rc2 = pBinding->InjectSend(skb, dev); |
902 |
#endif |
845 |
} |
903 |
} |
846 |
break; |
904 |
break; |
847 |
case CNI_CHAIN: |
905 |
case CNI_CHAIN: |
|
|
906 |
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,29) |
907 |
rc2 = pBinding->Inject_ops->ndo_start_xmit(skb, dev); |
908 |
#else |
848 |
rc2 = pBinding->InjectSend(skb, dev); |
909 |
rc2 = pBinding->InjectSend(skb, dev); |
|
|
910 |
#endif |
849 |
break; |
911 |
break; |
850 |
default: |
912 |
default: |
851 |
printk(KERN_DEBUG "Unhandled case in %s rc was %x\n", __FUNCTION__, |
913 |
printk(KERN_DEBUG "Unhandled case in %s rc was %x\n", __FUNCTION__, |
Lines 896-902
Link Here
|
896 |
//only need to handle IP packets. |
958 |
//only need to handle IP packets. |
897 |
if (skb->protocol != htons(ETH_P_IP)) |
959 |
if (skb->protocol != htons(ETH_P_IP)) |
898 |
{ |
960 |
{ |
|
|
961 |
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,29) |
962 |
rc2 = pBinding->Inject_ops->ndo_start_xmit(skb, dev); |
963 |
#else |
899 |
rc2 = pBinding->InjectSend(skb, dev); |
964 |
rc2 = pBinding->InjectSend(skb, dev); |
|
|
965 |
#endif |
900 |
goto exit_gracefully; |
966 |
goto exit_gracefully; |
901 |
} |
967 |
} |
902 |
|
968 |
|
Lines 924-933
Link Here
|
924 |
PCNI_CHARACTERISTICS PCNICallbackTable; |
990 |
PCNI_CHARACTERISTICS PCNICallbackTable; |
925 |
CNISTATUS rc = CNI_SUCCESS; |
991 |
CNISTATUS rc = CNI_SUCCESS; |
926 |
|
992 |
|
|
|
993 |
rc = CniPluginLoad(&pcDeviceName, &PCNICallbackTable); |
994 |
|
995 |
/* 2.6.24 needs to allocate each netdevice before registering it, otherwise |
996 |
* the kernel BUG()s. |
997 |
* |
998 |
* by Alexander Griesser <work@tuxx-home.at>, 2008-01-11 |
999 |
*/ |
927 |
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,24) |
1000 |
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,24) |
928 |
interceptor_dev= alloc_netdev( 0, interceptor_name, (void *)interceptor_init); |
1001 |
if(! (interceptor_dev = alloc_netdev(sizeof(struct net_device), interceptor_name, interceptor_init))) |
|
|
1002 |
return 0; |
929 |
#endif |
1003 |
#endif |
930 |
rc = CniPluginLoad(&pcDeviceName, &PCNICallbackTable); |
|
|
931 |
|
1004 |
|
932 |
if (CNI_IS_SUCCESS(rc)) |
1005 |
if (CNI_IS_SUCCESS(rc)) |
933 |
{ |
1006 |
{ |