1
1

Initial dump from Zyxel

This commit is contained in:
2026-04-17 17:00:52 +02:00
commit 81fec250f4
23116 changed files with 5231237 additions and 0 deletions
+185
View File
@@ -0,0 +1,185 @@
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);
+
+43
View File
@@ -0,0 +1,43 @@
diff -Naur nat46-6.old/nat46/modules/nat46-core.c nat46-6.new/nat46/modules/nat46-core.c
--- nat46-6.old/nat46/modules/nat46-core.c 2017-04-17 09:59:50.025700000 +0530
+++ nat46-6.new/nat46/modules/nat46-core.c 2017-04-17 10:11:16.107523000 +0530
@@ -807,11 +807,12 @@
}
void fill_v4hdr_from_v6hdr(struct iphdr * iph, struct ipv6hdr *ip6h, __u32 v4saddr, __u32 v4daddr, __u16 id, __u16 frag_off, __u16 proto, int l3_payload_len) {
+ uint32_t ver_class_flow = ntohl(*(__be32 *)ip6h);
iph->ttl = ip6h->hop_limit;
iph->saddr = v4saddr;
iph->daddr = v4daddr;
iph->protocol = proto;
- *((__be16 *)iph) = htons((4 << 12) | (5 << 8) | (0x00/*tos*/ & 0xff));
+ *((__be16 *)iph) = htons((4 << 12) | (5 << 8) | ((ver_class_flow >> 20) & 0xff));
iph->frag_off = frag_off;
iph->id = id;
iph->tot_len = htons( l3_payload_len + IPV4HDRSIZE );
@@ -1743,8 +1744,8 @@
nat46_instance_t *nat46 = get_nat46_instance(old_skb);
struct sk_buff *new_skb;
uint16_t sport = 0, dport = 0;
+ uint8_t tclass;
- int tclass = 0;
int flowlabel = 0;
int do_l4_translate = 0;
@@ -1752,6 +1753,7 @@
struct ipv6hdr * hdr6;
struct iphdr * hdr4 = ip_hdr(old_skb);
+ tclass = hdr4->tos;
char v6saddr[16], v6daddr[16];
@@ -1829,7 +1831,6 @@
memset(hdr6, 0, sizeof(*hdr6) + (add_frag_header?8:0));
/* build IPv6 header */
- tclass = 0; /* traffic class */
*(__be32 *)hdr6 = htonl(0x60000000 | (tclass << 20)) | flowlabel; /* version, priority, flowlabel */
/* IPv6 length is a payload length, IPv4 is hdr+payload */