Skip to content

Commit c31f993

Browse files
committed
Fix build failures observed so far
[fedora@fedora-41 modules]$ make make -C /lib/modules/6.12.11-200.fc41.x86_64/build M=/home/fedora/nat46/nat46/modules modules make[1]: Entering directory '/usr/src/kernels/6.12.11-200.fc41.x86_64' CC [M] /home/fedora/nat46/nat46/modules/nat46-netdev.o /home/fedora/nat46/nat46/modules/nat46-netdev.c: In function ‘nat46_netdev_setup’: /home/fedora/nat46/nat46/modules/nat46-netdev.c:113:25: error: ‘NETIF_F_NETNS_LOCAL’ undeclared (first use in this function) 113 | dev->features = NETIF_F_NETNS_LOCAL; | ^~~~~~~~~~~~~~~~~~~ /home/fedora/nat46/nat46/modules/nat46-netdev.c:113:25: note: each undeclared identifier is reported only once for each function it appears in /home/fedora/nat46/nat46/modules/nat46-netdev.c: At top level: /home/fedora/nat46/nat46/modules/nat46-netdev.c:117:5: warning: no previous prototype for ‘nat46_netdev_create’ [-Wmissing-prototypes] 117 | int nat46_netdev_create(struct net *net, char *basename, struct net_device **dev) | ^~~~~~~~~~~~~~~~~~~ /home/fedora/nat46/nat46/modules/nat46-netdev.c:173:6: warning: no previous prototype for ‘nat46_netdev_destroy’ [-Wmissing-prototypes] 173 | void nat46_netdev_destroy(struct net_device *dev) | ^~~~~~~~~~~~~~~~~~~~ In file included from ./include/linux/spinlock.h:305, from ./include/linux/sched.h:2153, from ./include/linux/percpu.h:12, from ./arch/x86/include/asm/msr.h:15, from ./arch/x86/include/asm/tsc.h:10, from ./arch/x86/include/asm/timex.h:6, from ./include/linux/timex.h:67, from ./include/linux/time32.h:13, from ./include/linux/time.h:60, from ./include/linux/skbuff.h:15, from ./include/linux/if_arp.h:22, from /home/fedora/nat46/nat46/modules/nat46-netdev.c:19: /home/fedora/nat46/nat46/modules/nat46-netdev.c: In function ‘find_dev’: /home/fedora/nat46/nat46/modules/nat46-netdev.c:196:20: error: ‘dev_base_lock’ undeclared (first use in this function); did you mean ‘device_lock’? 196 | read_lock(&dev_base_lock); | ^~~~~~~~~~~~~ ./include/linux/rwlock.h:56:48: note: in definition of macro ‘read_lock’ 56 | #define read_lock(lock) _raw_read_lock(lock) | ^~~~ /home/fedora/nat46/nat46/modules/nat46-netdev.c: In function ‘nat64_show_all_configs’: /home/fedora/nat46/nat46/modules/nat46-netdev.c:303:20: error: ‘dev_base_lock’ undeclared (first use in this function); did you mean ‘device_lock’? 303 | read_lock(&dev_base_lock); | ^~~~~~~~~~~~~ ./include/linux/rwlock.h:56:48: note: in definition of macro ‘read_lock’ 56 | #define read_lock(lock) _raw_read_lock(lock) | ^~~~ /home/fedora/nat46/nat46/modules/nat46-netdev.c: In function ‘nat46_destroy_all’: /home/fedora/nat46/nat46/modules/nat46-netdev.c:334:28: error: ‘dev_base_lock’ undeclared (first use in this function); did you mean ‘device_lock’? 334 | read_lock(&dev_base_lock); | ^~~~~~~~~~~~~ ./include/linux/rwlock.h:56:48: note: in definition of macro ‘read_lock’ 56 | #define read_lock(lock) _raw_read_lock(lock) | ^~~~ make[3]: *** [scripts/Makefile.build:229: /home/fedora/nat46/nat46/modules/nat46-netdev.o] Error 1 make[2]: *** [/usr/src/kernels/6.12.11-200.fc41.x86_64/Makefile:1977: /home/fedora/nat46/nat46/modules] Error 2 make[1]: *** [Makefile:236: __sub-make] Error 2 make[1]: Leaving directory '/usr/src/kernels/6.12.11-200.fc41.x86_64' make: *** [Makefile:6: all] Error 2 ubuntu@ubuntu-20:~/nat46/nat46/modules$ make make -C /lib/modules/5.4.0-205-generic/build M=/home/ubuntu/nat46/nat46/modules modules make[1]: Entering directory '/usr/src/linux-headers-5.4.0-205-generic' CC [M] /home/ubuntu/nat46/nat46/modules/nat46-netdev.o CC [M] /home/ubuntu/nat46/nat46/modules/nat46-module.o /home/ubuntu/nat46/nat46/modules/nat46-module.c: In function ‘nat46_init’: /home/ubuntu/nat46/nat46/modules/nat46-module.c:254:49: error: macro "__DATE__" might prevent reproducible builds [-Werror=date-time] 254 | printk("nat46: module (version %s) loaded.\n", NAT46_VERSION); | ^~~~~~~~~~~~~ /home/ubuntu/nat46/nat46/modules/nat46-module.c:54:23: error: macro "__TIME__" might prevent reproducible builds [-Werror=date-time] 54 | #define NAT46_VERSION __DATE__ " " __TIME__ | ^~~~~~~~ /home/ubuntu/nat46/nat46/modules/nat46-module.c:254:49: note: in expansion of macro ‘NAT46_VERSION’ 254 | printk("nat46: module (version %s) loaded.\n", NAT46_VERSION); | ^~~~~~~~~~~~~ cc1: some warnings being treated as errors make[2]: *** [scripts/Makefile.build:270: /home/ubuntu/nat46/nat46/modules/nat46-module.o] Error 1 make[1]: *** [Makefile:1778: /home/ubuntu/nat46/nat46/modules] Error 2 make[1]: Leaving directory '/usr/src/linux-headers-5.4.0-205-generic' make: *** [Makefile:6: all] Error 2
1 parent 1c0066a commit c31f993

File tree

4 files changed

+54
-43
lines changed

4 files changed

+54
-43
lines changed

nat46/modules/Makefile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ obj-m += nat46.o
22
nat46-objs := nat46-netdev.o nat46-module.o nat46-core.o nat46-glue.o
33
CFLAGS_nat46.o := -DDEBUG
44

5+
EXTRA_CFLAGS += -Wno-date-time
6+
57
all:
68
make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules
79

nat46/modules/nat46-core.c

Lines changed: 34 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
#include "nat46-core.h"
3030
#include "nat46-module.h"
3131

32-
void
32+
void static
3333
nat46debug_dump(nat46_instance_t *nat46, int level, void *addr, int len)
3434
{
3535
char tohex[] = "0123456789ABCDEF";
@@ -118,7 +118,7 @@ char *get_next_arg(char **ptail) {
118118
* Parse an IPv6 address (if pref_len is NULL), or prefix (if it isn't).
119119
* parses destructively (places \0 between address and prefix len)
120120
*/
121-
int try_parse_ipv6_prefix(struct in6_addr *pref, int *pref_len, char *arg) {
121+
static int try_parse_ipv6_prefix(struct in6_addr *pref, int *pref_len, char *arg) {
122122
int err = 0;
123123
char *arg_plen = strchr(arg, '/');
124124
if (arg_plen) {
@@ -131,7 +131,7 @@ int try_parse_ipv6_prefix(struct in6_addr *pref, int *pref_len, char *arg) {
131131
return err;
132132
}
133133

134-
int try_parse_ipv4_prefix(u32 *v4addr, int *pref_len, char *arg) {
134+
static int try_parse_ipv4_prefix(u32 *v4addr, int *pref_len, char *arg) {
135135
int err = 0;
136136
char *arg_plen = strchr(arg, '/');
137137
if (arg_plen) {
@@ -151,7 +151,7 @@ int try_parse_ipv4_prefix(u32 *v4addr, int *pref_len, char *arg) {
151151
* destructive.
152152
*/
153153

154-
int try_parse_rule_arg(nat46_xlate_rule_t *rule, char *arg_name, char **ptail) {
154+
static int try_parse_rule_arg(nat46_xlate_rule_t *rule, char *arg_name, char **ptail) {
155155
int err = 0;
156156
char *val = get_next_arg(ptail);
157157
if (NULL == val) {
@@ -225,7 +225,7 @@ int nat46_set_config(nat46_instance_t *nat46, char *buf, int count) {
225225
return ret;
226226
}
227227

228-
char *xlate_style_to_string(nat46_xlate_style_t style) {
228+
static char *xlate_style_to_string(nat46_xlate_style_t style) {
229229
switch(style) {
230230
case NAT46_XLATE_NONE:
231231
return "NONE";
@@ -372,7 +372,7 @@ From RFC6052, section 2.2:
372372
373373
********************************************************************/
374374

375-
void xlate_v4_to_nat64(nat46_instance_t *nat46, nat46_xlate_rule_t *rule, void *pipv4, void *pipv6) {
375+
static void xlate_v4_to_nat64(nat46_instance_t *nat46, nat46_xlate_rule_t *rule, void *pipv4, void *pipv6) {
376376
char *ipv4 = pipv4;
377377
char *ipv6 = pipv6;
378378

@@ -413,7 +413,7 @@ void xlate_v4_to_nat64(nat46_instance_t *nat46, nat46_xlate_rule_t *rule, void *
413413
}
414414
}
415415

416-
int xlate_nat64_to_v4(nat46_instance_t *nat46, nat46_xlate_rule_t *rule, void *pipv6, void *pipv4) {
416+
static int xlate_nat64_to_v4(nat46_instance_t *nat46, nat46_xlate_rule_t *rule, void *pipv6, void *pipv4) {
417417
char *ipv4 = pipv4;
418418
char *ipv6 = pipv6;
419419
int cmp = -1;
@@ -597,7 +597,7 @@ bitarray_copy(const void *src_org, int src_offset, int src_len,
597597
}
598598
}
599599

600-
int xlate_map_v4_to_v6(nat46_instance_t *nat46, nat46_xlate_rule_t *rule, void *pipv4, void *pipv6, uint16_t *pl4id, int map_version) {
600+
static int xlate_map_v4_to_v6(nat46_instance_t *nat46, nat46_xlate_rule_t *rule, void *pipv4, void *pipv6, uint16_t *pl4id, int map_version) {
601601
int ret = 0;
602602
u32 *pv4u32 = pipv4;
603603
uint8_t *p6 = pipv6;
@@ -699,7 +699,7 @@ int xlate_map_v4_to_v6(nat46_instance_t *nat46, nat46_xlate_rule_t *rule, void *
699699
return ret;
700700
}
701701

702-
int xlate_map_v6_to_v4(nat46_instance_t *nat46, nat46_xlate_rule_t *rule, void *pipv6, void *pipv4, int version) {
702+
static int xlate_map_v6_to_v4(nat46_instance_t *nat46, nat46_xlate_rule_t *rule, void *pipv6, void *pipv4, int version) {
703703
uint8_t v4_lsb_bits_len = 32 - rule->v4_pref_len;
704704

705705
if (memcmp(pipv6, &rule->v6_pref, rule->v6_pref_len/8)) {
@@ -734,7 +734,7 @@ int xlate_map_v6_to_v4(nat46_instance_t *nat46, nat46_xlate_rule_t *rule, void *
734734
return 1;
735735
}
736736

737-
int xlate_v4_to_v6(nat46_instance_t *nat46, nat46_xlate_rule_t *rule, void *pipv4, void *pipv6, uint16_t *pl4id) {
737+
static int xlate_v4_to_v6(nat46_instance_t *nat46, nat46_xlate_rule_t *rule, void *pipv4, void *pipv6, uint16_t *pl4id) {
738738
int ret = 0;
739739
switch(rule->style) {
740740
case NAT46_XLATE_NONE: /* always fail unless it is a host 1:1 translation */
@@ -759,7 +759,7 @@ int xlate_v4_to_v6(nat46_instance_t *nat46, nat46_xlate_rule_t *rule, void *pipv
759759
return ret;
760760
}
761761

762-
int xlate_v6_to_v4(nat46_instance_t *nat46, nat46_xlate_rule_t *rule, void *pipv6, void *pipv4) {
762+
static int xlate_v6_to_v4(nat46_instance_t *nat46, nat46_xlate_rule_t *rule, void *pipv6, void *pipv4) {
763763
int ret = 0;
764764
switch(rule->style) {
765765
case NAT46_XLATE_NONE: /* always fail unless it is a host 1:1 translation */
@@ -782,7 +782,7 @@ int xlate_v6_to_v4(nat46_instance_t *nat46, nat46_xlate_rule_t *rule, void *pipv
782782
return ret;
783783
}
784784

785-
__sum16 csum16_upd(__sum16 csum, u16 old, u16 new) {
785+
static __sum16 csum16_upd(__sum16 csum, u16 old, u16 new) {
786786
u32 s;
787787
csum = ntohs(~csum);
788788
s = (u32)csum + ntohs(~old) + ntohs(new);
@@ -793,7 +793,7 @@ __sum16 csum16_upd(__sum16 csum, u16 old, u16 new) {
793793

794794
/* Add the TCP/UDP pseudoheader, basing on the existing checksum */
795795

796-
__sum16 csum_tcpudp_remagic(__be32 saddr, __be32 daddr, u32 len,
796+
static __sum16 csum_tcpudp_remagic(__be32 saddr, __be32 daddr, u32 len,
797797
unsigned char proto, u16 csum) {
798798
u16 *pdata;
799799
u16 len0, len1;
@@ -814,7 +814,7 @@ __sum16 csum_tcpudp_remagic(__be32 saddr, __be32 daddr, u32 len,
814814
}
815815

816816
/* Undo the IPv6 pseudoheader inclusion into the checksum */
817-
__sum16 csum_ipv6_unmagic(nat46_instance_t *nat46, const struct in6_addr *saddr,
817+
static __sum16 csum_ipv6_unmagic(nat46_instance_t *nat46, const struct in6_addr *saddr,
818818
const struct in6_addr *daddr,
819819
__u32 len, unsigned short proto,
820820
__sum16 csum) {
@@ -841,7 +841,7 @@ __sum16 csum_ipv6_unmagic(nat46_instance_t *nat46, const struct in6_addr *saddr,
841841
}
842842

843843
/* Update ICMPv6 type/code with incremental checksum adjustment */
844-
void update_icmp6_type_code(nat46_instance_t *nat46, struct icmp6hdr *icmp6h, u8 type, u8 code) {
844+
static void update_icmp6_type_code(nat46_instance_t *nat46, struct icmp6hdr *icmp6h, u8 type, u8 code) {
845845
u16 old_tc = *((u16 *)icmp6h);
846846
u16 new_tc;
847847
u16 old_csum = icmp6h->icmp6_cksum;
@@ -856,22 +856,22 @@ void update_icmp6_type_code(nat46_instance_t *nat46, struct icmp6hdr *icmp6h, u8
856856
}
857857

858858

859-
u16 get_next_ip_id(void) {
859+
static u16 get_next_ip_id(void) {
860860
static u16 id = 0;
861861
return id++;
862862
}
863863

864-
u16 fold_ipv6_frag_id(u32 v6id) {
864+
static u16 fold_ipv6_frag_id(u32 v6id) {
865865
return ((0xffff & (v6id >> 16)) ^ (v6id & 0xffff));
866866
}
867867

868-
void *add_offset(void *ptr, u16 offset) {
868+
static void *add_offset(void *ptr, u16 offset) {
869869
return (((char *)ptr)+offset);
870870
}
871871

872872

873873
/* FIXME: traverse the headers properly */
874-
void *get_next_header_ptr6(void *pv6, int v6_len) {
874+
static void *get_next_header_ptr6(void *pv6, int v6_len) {
875875
struct ipv6hdr *ip6h = pv6;
876876
void *ret = (ip6h+1);
877877

@@ -885,7 +885,7 @@ void *get_next_header_ptr6(void *pv6, int v6_len) {
885885
return ret;
886886
}
887887

888-
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) {
888+
static 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) {
889889
iph->ttl = ip6h->hop_limit;
890890
iph->saddr = v4saddr;
891891
iph->daddr = v4daddr;
@@ -898,7 +898,7 @@ void fill_v4hdr_from_v6hdr(struct iphdr * iph, struct ipv6hdr *ip6h, __u32 v4sad
898898
iph->check = ip_fast_csum((unsigned char *)iph, iph->ihl);
899899
}
900900

901-
u16 unchecksum16(void *p, int count, u16 csum) {
901+
static u16 unchecksum16(void *p, int count, u16 csum) {
902902
u16 *pu16 = p;
903903
int i = count;
904904
while(i--) {
@@ -907,7 +907,7 @@ u16 unchecksum16(void *p, int count, u16 csum) {
907907
return csum;
908908
}
909909

910-
u16 rechecksum16(void *p, int count, u16 csum) {
910+
static u16 rechecksum16(void *p, int count, u16 csum) {
911911
u16 *pu16 = p;
912912
int i = count;
913913
while(i--) {
@@ -917,11 +917,11 @@ u16 rechecksum16(void *p, int count, u16 csum) {
917917
}
918918

919919
/* Last rule in group must not have "none" as either source or destination */
920-
int is_last_pair_in_group(nat46_xlate_rulepair_t *apair) {
920+
static int is_last_pair_in_group(nat46_xlate_rulepair_t *apair) {
921921
return ( (apair->local.style != NAT46_XLATE_NONE) && (apair->remote.style != NAT46_XLATE_NONE) );
922922
}
923923

924-
void pairs_xlate_v6_to_v4_inner(nat46_instance_t *nat46, struct ipv6hdr *ip6h, __u32 *pv4saddr, __u32 *pv4daddr) {
924+
static void pairs_xlate_v6_to_v4_inner(nat46_instance_t *nat46, struct ipv6hdr *ip6h, __u32 *pv4saddr, __u32 *pv4daddr) {
925925
int ipair = 0;
926926
nat46_xlate_rulepair_t *apair = NULL;
927927
int xlate_src = -1;
@@ -959,7 +959,7 @@ void pairs_xlate_v6_to_v4_inner(nat46_instance_t *nat46, struct ipv6hdr *ip6h, _
959959
* Translate this header and attempt to extract the sport/dport
960960
* so the callers can use them for translation as well.
961961
*/
962-
int xlate_payload6_to4(nat46_instance_t *nat46, void *pv6, void *ptrans_hdr, int v6_len, u16 *ul_sum, int *ptailTruncSize) {
962+
static int xlate_payload6_to4(nat46_instance_t *nat46, void *pv6, void *ptrans_hdr, int v6_len, u16 *ul_sum, int *ptailTruncSize) {
963963
struct ipv6hdr *ip6h = pv6;
964964
__u32 v4saddr, v4daddr;
965965
struct iphdr new_ipv4;
@@ -1049,12 +1049,12 @@ int xlate_payload6_to4(nat46_instance_t *nat46, void *pv6, void *ptrans_hdr, int
10491049
return (v6_len - IPV6V4HDRDELTA);
10501050
}
10511051

1052-
u8 *icmp_parameter_ptr(struct icmphdr *icmph) {
1052+
static u8 *icmp_parameter_ptr(struct icmphdr *icmph) {
10531053
u8 *icmp_pptr = ((u8 *)(icmph))+4;
10541054
return icmp_pptr;
10551055
}
10561056

1057-
u32 *icmp6_parameter_ptr(struct icmp6hdr *icmp6h) {
1057+
static u32 *icmp6_parameter_ptr(struct icmp6hdr *icmp6h) {
10581058
u32 *icmp6_pptr = ((u32 *)(icmp6h))+1;
10591059
return icmp6_pptr;
10601060
}
@@ -1282,7 +1282,7 @@ static void nat46_fixup_icmp6(nat46_instance_t *nat46, struct ipv6hdr *ip6h, str
12821282
}
12831283

12841284

1285-
int ip6_input_not_interested(nat46_instance_t *nat46, struct ipv6hdr *ip6h, struct sk_buff *old_skb) {
1285+
static int ip6_input_not_interested(nat46_instance_t *nat46, struct ipv6hdr *ip6h, struct sk_buff *old_skb) {
12861286
if (old_skb->protocol != htons(ETH_P_IPV6)) {
12871287
nat46debug(3, "Not an IPv6 packet");
12881288
return 1;
@@ -1533,7 +1533,7 @@ static uint16_t nat46_fixup_icmp(nat46_instance_t *nat46, struct iphdr *iph, str
15331533
return ret;
15341534
}
15351535

1536-
int pairs_xlate_v6_to_v4_outer(nat46_instance_t *nat46, struct ipv6hdr *ip6h, uint16_t proto, __u32 *pv4saddr, __u32 *pv4daddr) {
1536+
static int pairs_xlate_v6_to_v4_outer(nat46_instance_t *nat46, struct ipv6hdr *ip6h, uint16_t proto, __u32 *pv4saddr, __u32 *pv4daddr) {
15371537
int ipair = 0;
15381538
nat46_xlate_rulepair_t *apair = NULL;
15391539
int xlate_src = -1;
@@ -1743,7 +1743,7 @@ int nat46_ipv6_input(struct sk_buff *old_skb) {
17431743

17441744

17451745

1746-
void ip6_update_csum(struct sk_buff * skb, struct ipv6hdr * ip6hdr, int do_atomic_frag)
1746+
static void ip6_update_csum(struct sk_buff * skb, struct ipv6hdr * ip6hdr, int do_atomic_frag)
17471747
{
17481748
u32 sum1=0;
17491749
u16 sum2=0;
@@ -1767,8 +1767,8 @@ void ip6_update_csum(struct sk_buff * skb, struct ipv6hdr * ip6hdr, int do_atomi
17671767
unsigned udplen = ntohs(ip6hdr->payload_len) - (do_atomic_frag?8:0); /* UDP hdr + payload */
17681768

17691769
if ((udp->check == 0) && zero_csum_pass) {
1770-
/* zero checksum and the config to pass it is set - do nothing with it */
1771-
break;
1770+
/* zero checksum and the config to pass it is set - do nothing with it */
1771+
break;
17721772
}
17731773

17741774
oldsum = udp->check;
@@ -1797,7 +1797,7 @@ void ip6_update_csum(struct sk_buff * skb, struct ipv6hdr * ip6hdr, int do_atomi
17971797
}
17981798
}
17991799

1800-
int ip4_input_not_interested(nat46_instance_t *nat46, struct iphdr *iph, struct sk_buff *old_skb) {
1800+
static int ip4_input_not_interested(nat46_instance_t *nat46, struct iphdr *iph, struct sk_buff *old_skb) {
18011801
if (old_skb->protocol != htons(ETH_P_IP)) {
18021802
nat46debug(3, "Not an IPv4 packet");
18031803
return 1;
@@ -1806,7 +1806,7 @@ int ip4_input_not_interested(nat46_instance_t *nat46, struct iphdr *iph, struct
18061806
return 0;
18071807
}
18081808

1809-
int pairs_xlate_v4_to_v6_outer(nat46_instance_t *nat46, struct iphdr *hdr4, uint16_t *sport, uint16_t *dport, void *v6saddr, void *v6daddr) {
1809+
static int pairs_xlate_v4_to_v6_outer(nat46_instance_t *nat46, struct iphdr *hdr4, uint16_t *sport, uint16_t *dport, void *v6saddr, void *v6daddr) {
18101810
int ipair = 0;
18111811
nat46_xlate_rulepair_t *apair = NULL;
18121812
int xlate_src = -1;

nat46/modules/nat46-glue.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
#include "nat46-core.h"
2020

2121
static DEFINE_MUTEX(ref_lock);
22-
int is_valid_nat46(nat46_instance_t *nat46) {
22+
static int is_valid_nat46(nat46_instance_t *nat46) {
2323
return (nat46 && (nat46->sig == NAT46_SIGNATURE));
2424
}
2525

nat46/modules/nat46-netdev.c

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818

1919
#include <linux/if_arp.h>
20+
#include <linux/netdev_features.h>
2021
#include <linux/netdevice.h>
2122
#include <linux/route.h>
2223
#include <linux/skbuff.h>
@@ -29,6 +30,14 @@
2930

3031
#define NETDEV_DEFAULT_NAME "nat46."
3132

33+
#if LINUX_VERSION_CODE >= KERNEL_VERSION(6, 9, 0)
34+
#define dev_lock_list() rcu_read_lock()
35+
#define dev_unlock_list() rcu_read_unlock()
36+
#else
37+
#define dev_lock_list() read_lock(&dev_base_lock)
38+
#define dev_unlock_list() read_unlock(&dev_base_lock)
39+
#endif
40+
3241
typedef struct {
3342
u32 sig;
3443
nat46_instance_t *nat46;
@@ -114,7 +123,7 @@ static void nat46_netdev_setup(struct net_device *dev)
114123
dev->flags = IFF_NOARP | IFF_POINTOPOINT;
115124
}
116125

117-
int nat46_netdev_create(struct net *net, char *basename, struct net_device **dev)
126+
static int nat46_netdev_create(struct net *net, char *basename, struct net_device **dev)
118127
{
119128
int ret = 0;
120129
char *devname = NULL;
@@ -170,7 +179,7 @@ int nat46_netdev_create(struct net *net, char *basename, struct net_device **dev
170179
return ret;
171180
}
172181

173-
void nat46_netdev_destroy(struct net_device *dev)
182+
static void nat46_netdev_destroy(struct net_device *dev)
174183
{
175184
dev->flags &= ~IFF_UP;
176185
netif_stop_queue(dev);
@@ -193,7 +202,7 @@ static struct net_device *find_dev(struct net *net, char *name) {
193202
return NULL;
194203
}
195204

196-
read_lock(&dev_base_lock);
205+
dev_lock_list();
197206
dev = first_net_device(net);
198207
while (dev) {
199208
if((0 == strcmp(dev->name, name)) && is_nat46(dev)) {
@@ -205,7 +214,7 @@ static struct net_device *find_dev(struct net *net, char *name) {
205214
}
206215
dev = next_net_device(dev);
207216
}
208-
read_unlock(&dev_base_lock);
217+
dev_unlock_list();
209218
return out;
210219
}
211220

@@ -300,7 +309,7 @@ int nat46_remove(struct net *net, char *devname, char *buf) {
300309

301310
void nat64_show_all_configs(struct net *net, struct seq_file *m) {
302311
struct net_device *dev;
303-
read_lock(&dev_base_lock);
312+
dev_lock_list();
304313
dev = first_net_device(net);
305314
while (dev) {
306315
if(is_nat46(dev)) {
@@ -323,15 +332,15 @@ void nat64_show_all_configs(struct net *net, struct seq_file *m) {
323332
}
324333
dev = next_net_device(dev);
325334
}
326-
read_unlock(&dev_base_lock);
335+
dev_unlock_list();
327336

328337
}
329338

330339
void nat46_destroy_all(struct net *net) {
331340
struct net_device *dev;
332341
struct net_device *nat46dev;
333342
do {
334-
read_lock(&dev_base_lock);
343+
dev_lock_list();
335344
nat46dev = NULL;
336345
dev = first_net_device(net);
337346
while (dev) {
@@ -340,7 +349,7 @@ void nat46_destroy_all(struct net *net) {
340349
}
341350
dev = next_net_device(dev);
342351
}
343-
read_unlock(&dev_base_lock);
352+
dev_unlock_list();
344353
if(nat46dev) {
345354
nat46_netdev_destroy(nat46dev);
346355
}

0 commit comments

Comments
 (0)