wifidog-ng: Update to 2.0.1 9450/head
authorJianhui Zhao <jianhuizhao329@gmail.com>
Thu, 11 Jul 2019 08:29:15 +0000 (16:29 +0800)
committerJianhui Zhao <jianhuizhao329@gmail.com>
Thu, 11 Jul 2019 08:29:40 +0000 (16:29 +0800)
Compatible with Linux kernel 4.18 and above

Signed-off-by: Jianhui Zhao <jianhuizhao329@gmail.com>
net/wifidog-ng/Makefile
net/wifidog-ng/src/main.c

index 3909e2a13c9a766c88712f3f4bd7d340878ddfb0..c936e3ad5c0ad25835139f3d0499f550e20e1928 100644 (file)
@@ -8,8 +8,8 @@
 include $(TOPDIR)/rules.mk
 
 PKG_NAME:=wifidog-ng
-PKG_VERSION:=2.0.0
-PKG_RELEASE:=2
+PKG_VERSION:=2.0.1
+PKG_RELEASE:=1
 
 PKG_BUILD_DIR=$(BUILD_DIR)/$(PKG_NAME)-$(BUILD_VARIANT)
 
index 96da9a667fc7faa5f76361a16acd0fc6d2da1018..afb1b038ed6a8be41378860742d0a39aed832410 100644 (file)
 #define IPS_HIJACKED    (1 << 31)
 #define IPS_ALLOWED     (1 << 30)
 
-static u32 wd_nf_nat_setup_info(void *priv, struct sk_buff *skb,
+#if LINUX_VERSION_CODE > KERNEL_VERSION(4, 17, 19)
+static u32 wd_nat_setup_info(struct sk_buff *skb, struct nf_conn *ct)
+#else
+static u32 wd_nat_setup_info(void *priv, struct sk_buff *skb,
     const struct nf_hook_state *state, struct nf_conn *ct)
+#endif
 {
     struct config *conf = get_config();
     struct tcphdr *tcph = tcp_hdr(skb);
     union nf_conntrack_man_proto proto;
-    struct nf_nat_range newrange;
+#if LINUX_VERSION_CODE > KERNEL_VERSION(4, 17, 19)
+    struct nf_nat_range2 newrange = {};
+#else
+    struct nf_nat_range newrange = {};
+#endif
     static uint16_t PORT_80 = htons(80);
 
     proto.tcp.port = (tcph->dest == PORT_80) ? htons(conf->port) : htons(conf->ssl_port);
     newrange.flags       = NF_NAT_RANGE_MAP_IPS | NF_NAT_RANGE_PROTO_SPECIFIED;
-    newrange.min_addr.ip = newrange.max_addr.ip = conf->interface_ipaddr;
-    newrange.min_proto   = newrange.max_proto = proto;
+    newrange.min_addr.ip = conf->interface_ipaddr;
+    newrange.max_addr.ip = conf->interface_ipaddr;
+    newrange.min_proto   = proto;
+    newrange.max_proto   = proto;
 
     ct->status |= IPS_HIJACKED;
 
@@ -117,16 +127,18 @@ redirect:
         return NF_DROP;
     }
 
-    return nf_nat_ipv4_in(priv, skb, state, wd_nf_nat_setup_info);
+#if LINUX_VERSION_CODE > KERNEL_VERSION(4, 17, 19)
+    return wd_nat_setup_info(skb, ct);
+#else
+    return nf_nat_ipv4_in(priv, skb, state, wd_nat_setup_info);
+#endif
 }
 
-static struct nf_hook_ops wifidog_ops[] __read_mostly = {
-    {
-        .hook       = wifidog_hook,
-        .pf         = PF_INET,
-        .hooknum    = NF_INET_PRE_ROUTING,
-        .priority   = NF_IP_PRI_CONNTRACK + 1 /* after conntrack */
-    }
+static struct nf_hook_ops wifidog_ops __read_mostly = {
+    .hook       = wifidog_hook,
+    .pf         = PF_INET,
+    .hooknum    = NF_INET_PRE_ROUTING,
+    .priority   = NF_IP_PRI_NAT_DST
 };
 
 static int __init wifidog_init(void)
@@ -137,10 +149,12 @@ static int __init wifidog_init(void)
     if (ret)
         return ret;
 
-#if LINUX_VERSION_CODE > KERNEL_VERSION(4, 12, 14)
-    ret = nf_register_net_hooks(&init_net, wifidog_ops, ARRAY_SIZE(wifidog_ops));
+#if LINUX_VERSION_CODE > KERNEL_VERSION(4, 17, 19)
+    ret = nf_nat_l3proto_ipv4_register_fn(&init_net, &wifidog_ops);
+#elif LINUX_VERSION_CODE > KERNEL_VERSION(4, 12, 14)
+    ret = nf_register_net_hook(&init_net, &wifidog_ops);
 #else
-    ret = nf_register_hooks(wifidog_ops, ARRAY_SIZE(wifidog_ops));
+    ret = nf_register_hook(&wifidog_ops);
 #endif
     if (ret < 0) {
         pr_err("can't register hook\n");
@@ -160,10 +174,12 @@ static void __exit wifidog_exit(void)
 {
     deinit_config();
 
-#if LINUX_VERSION_CODE > KERNEL_VERSION(4, 12, 14)
-    nf_unregister_net_hooks(&init_net, wifidog_ops, ARRAY_SIZE(wifidog_ops));
+#if LINUX_VERSION_CODE > KERNEL_VERSION(4, 17, 19)
+    nf_nat_l3proto_ipv4_unregister_fn(&init_net, &wifidog_ops);
+#elif LINUX_VERSION_CODE > KERNEL_VERSION(4, 12, 14)
+    nf_unregister_net_hook(&init_net, &wifidog_ops);
 #else
-    nf_unregister_hooks(wifidog_ops, ARRAY_SIZE(wifidog_ops));
+    nf_unregister_hook(&wifidog_ops);
 #endif
 
     pr_info("kmod of wifidog-ng is stop\n");