1
0
This repository has been archived on 2024-07-22. You can view files and clone it, but cannot push or open issues or pull requests.
Files

186 lines
5.9 KiB
Diff
Executable File

diff -NaurwB old/nat46/modules/nat46-core.c new/nat46/modules/nat46-core.c
--- old/nat46/modules/nat46-core.c 2015-12-11 09:18:08.344665000 +0530
+++ new/nat46/modules/nat46-core.c 2016-03-18 18:31:46.116736000 +0530
@@ -1488,6 +1488,10 @@
return ( (xlate_src >= 0) && (xlate_dst >= 0) );
}
+int xlate_6_to_4(struct net_device *dev, struct ipv6hdr *ip6h, uint16_t proto, __u32 *pv4saddr, __u32 *pv4daddr) {
+ return pairs_xlate_v6_to_v4_outer(netdev_nat46_instance(dev), ip6h, proto, pv4saddr, pv4daddr);
+}
+EXPORT_SYMBOL(xlate_6_to_4);
void nat46_ipv6_input(struct sk_buff *old_skb) {
struct ipv6hdr *ip6h = ipv6_hdr(old_skb);
@@ -1626,6 +1630,10 @@
nat46debug(5, "about to send v4 packet, flags: %02x", IPCB(new_skb)->flags);
nat46_netdev_count_xmit(new_skb, old_skb->dev);
+
+ /* set skb->iif */
+ new_skb->skb_iif = old_skb->skb_iif;
+
netif_rx(new_skb);
/* TBD: should copy be released here? */
@@ -1725,6 +1733,10 @@
return ret;
}
+int xlate_4_to_6(struct net_device *dev, struct iphdr *hdr4, int sport, int dport, void *v6saddr, void *v6daddr) {
+ return pairs_xlate_v4_to_v6_outer(netdev_nat46_instance(dev), hdr4, sport, dport, v6saddr, v6daddr);
+}
+EXPORT_SYMBOL(xlate_4_to_6);
void nat46_ipv4_input(struct sk_buff *old_skb) {
nat46_instance_t *nat46 = get_nat46_instance(old_skb);
@@ -1841,10 +1858,32 @@
new_skb->dev = old_skb->dev;
nat46_netdev_count_xmit(new_skb, old_skb->dev);
+
+ /* set skb->iif */
+ new_skb->skb_iif = old_skb->skb_iif;
+
netif_rx(new_skb);
done:
release_nat46_instance(nat46);
}
-
+int nat46_get_npairs(struct net_device *dev) {
+ nat46_instance_t *nat46 = netdev_nat46_instance(dev);
+ return nat46->npairs;
+}
+EXPORT_SYMBOL(nat46_get_npairs);
+
+bool nat46_get_rule_config(struct net_device *dev, nat46_xlate_rulepair_t **nat46_rule_pair, int *count) {
+ nat46_instance_t *nat46 = netdev_nat46_instance(dev);
+ if (nat46->npairs < 1) {
+ /*
+ * no rules ?
+ */
+ return false;
+ }
+ *count = nat46->npairs;
+ *nat46_rule_pair = nat46->pairs;
+ return true;
+}
+EXPORT_SYMBOL(nat46_get_rule_config);
diff -NaurwB old/nat46/modules/nat46-core.h new/nat46/modules/nat46-core.h
--- old/nat46/modules/nat46-core.h 2015-12-11 09:18:08.346667000 +0530
+++ new/nat46/modules/nat46-core.h 2016-03-18 09:24:39.180298000 +0530
@@ -42,7 +42,7 @@
#define NAT46_SIGNATURE 0x544e3634
#define FREED_NAT46_SIGNATURE 0xdead544e
-typedef struct {
+typedef struct nat46_xlate_rule {
nat46_xlate_style_t style;
struct in6_addr v6_pref;
int v6_pref_len;
@@ -53,7 +53,7 @@
int fmr_flag;
} nat46_xlate_rule_t;
-typedef struct {
+typedef struct nat46_xlate_rulepair {
nat46_xlate_rule_t local;
nat46_xlate_rule_t remote;
} nat46_xlate_rulepair_t;
@@ -82,4 +82,10 @@
nat46_instance_t *alloc_nat46_instance(int npairs, nat46_instance_t *old, int from_ipair, int to_ipair);
void release_nat46_instance(nat46_instance_t *nat46);
+int xlate_6_to_4(struct net_device *dev, struct ipv6hdr *ip6h, uint16_t proto, __u32 *pv4saddr, __u32 *pv4daddr);
+int xlate_4_to_6(struct net_device *dev, struct iphdr *hdr4, int sport, int dport, void *v6saddr, void *v6daddr);
+bool nat46_get_rule_config(struct net_device *dev, nat46_xlate_rulepair_t **nat46_rule_pair, int *count);
+int nat46_get_npairs(struct net_device *dev);
+
+
#endif
diff -NaurwB old/nat46/modules/nat46-netdev.c new/nat46/modules/nat46-netdev.c
--- old/nat46/modules/nat46-netdev.c 2015-12-11 09:18:08.354664000 +0530
+++ new/nat46/modules/nat46-netdev.c 2016-03-18 18:30:34.080453000 +0530
@@ -23,10 +23,12 @@
#include <net/ip6_route.h>
#include <net/ipv6.h>
#include <linux/version.h>
+#include <linux/radix-tree.h>
#include "nat46-core.h"
#include "nat46-module.h"
#define NETDEV_DEFAULT_NAME "nat46."
+static RADIX_TREE(netdev_tree, GFP_ATOMIC);
typedef struct {
u32 sig;
@@ -78,6 +80,19 @@
dev->stats.tx_bytes += skb->len;
}
+
+void nat46_update_stats(struct net_device *dev, uint32_t rx_packets, uint32_t rx_bytes,
+ uint32_t tx_packets, uint32_t tx_bytes, uint32_t rx_dropped, uint32_t tx_dropped)
+{
+ dev->stats.rx_packets += rx_packets;
+ dev->stats.rx_bytes += rx_bytes;
+ dev->stats.tx_packets += tx_packets;
+ dev->stats.tx_bytes += tx_bytes;
+ dev->stats.rx_dropped += rx_dropped;
+ dev->stats.tx_dropped += tx_dropped;
+}
+EXPORT_SYMBOL(nat46_update_stats);
+
void *netdev_nat46_instance(struct net_device *dev) {
nat46_netdev_priv_t *priv = netdev_priv(dev);
return priv->nat46;
@@ -150,6 +165,11 @@
printk("nat46: netdevice nat46 '%s' created successfully.\n", devname);
kfree(devname);
+ /*
+ * add this netdevice to list
+ */
+ radix_tree_insert(&netdev_tree, (*dev)->ifindex, (void *)*dev);
+
return 0;
err_register_dev:
@@ -164,9 +184,23 @@
{
netdev_nat46_set_instance(dev, NULL);
unregister_netdev(dev);
+ radix_tree_delete(&netdev_tree, dev->ifindex);
printk("nat46: Destroying nat46 device.\n");
}
+bool is_map_t_dev(struct net_device *dev)
+{
+ if(!dev) {
+ return false;
+ }
+
+ if(radix_tree_lookup(&netdev_tree, dev->ifindex)) {
+ return true;
+ }
+ return false;
+}
+EXPORT_SYMBOL(is_map_t_dev);
+
static int is_nat46(struct net_device *dev) {
nat46_netdev_priv_t *priv = netdev_priv(dev);
return (priv && (NAT46_DEVICE_SIGNATURE == priv->sig));
diff -NaurwB old/nat46/modules/nat46-netdev.h new/nat46/modules/nat46-netdev.h
--- old/nat46/modules/nat46-netdev.h 2015-12-11 09:18:08.355665000 +0530
+++ new/nat46/modules/nat46-netdev.h 2016-03-15 08:11:32.171420000 +0530
@@ -24,3 +24,7 @@
void nat46_netdev_count_xmit(struct sk_buff *skb, struct net_device *dev);
void *netdev_nat46_instance(struct net_device *dev);
+void nat46_update_stats(struct net_device *dev, uint32_t rx_packets, uint32_t rx_bytes, uint32_t tx_packets, uint32_t tx_bytes,
+ uint32_t rx_dropped, uint32_t tx_dropped);
+bool is_map_t_dev(struct net_device *dev);
+