因为开发板要充当热点,要用iptables把wlan转发到eth上,结果发现没有iptables
1.直接从网站下了一个iptables
写BUILD.gn
import("//build/ohos.gni")
config("iptables_config") {
cflags = [
"-D_LARGEFILE_SOURCE=1",
"-D_LARGE_FILES",
"-D_FILE_OFFSET_BITS=64",
"-D_REENTRANT",
"-DENABLE_IPV4",
"-DENABLE_IPV6",
"-Wall",
"-Wno-error",
"-Wno-pointer-arith",
"-Wno-sign-compare",
"-Wno-unused-parameter",
"-Wno-missing-field-initializers",
"-Wno-parentheses-equality",
"-DNO_SHARED_LIBS=1",
"-DALL_INCLUSIVE",
"-DXTABLES_INTERNAL",
]
}
ohos_executable("iptables") {
sources = [
"//third_party/iptables/iptables/ip6tables-standalone.c",
"//third_party/iptables/iptables/ip6tables.c",
"//third_party/iptables/iptables/iptables-restore.c",
"//third_party/iptables/iptables/iptables-save.c",
"//third_party/iptables/iptables/iptables-standalone.c",
"//third_party/iptables/iptables/iptables-xml.c",
"//third_party/iptables/iptables/iptables.c",
"//third_party/iptables/iptables/xshared.c",
"//third_party/iptables/iptables/xtables-legacy-multi.c",
]
include_dirs = [
"//third_party/iptables",
"//third_party/iptables/extensions",
"//third_party/iptables/include",
"//third_party/iptables/iptables",
"//third_party/iptables/libiptc",
]
configs = [ ":iptables_config" ]
install_enable = true
deps = [
"//third_party/iptables/extensions:libext",
"//third_party/iptables/extensions:libext4",
"//third_party/iptables/extensions:libext6",
"//third_party/iptables/libiptc:libip4tc",
"//third_party/iptables/libiptc:libip6tc",
"//third_party/iptables/libxtables:libxtables",
]
part_name = "netmanager_base"
subsystem_name = "communication"
}
2.配置内核,按网站配置内核
[] Networking support —> [CONFIG_NET]
Networking Options —>
[] Network packet filtering framework (Netfilter) —> [CONFIG_NETFILTER]
[] Advanced netfilter configuration [CONFIG_NETFILTER_ADVANCED]
Core Netfilter Configuration —>
</M> Netfilter connection tracking support [CONFIG_NF_CONNTRACK]
</M> Netfilter Xtables support (required for ip_tables) [CONFIG_NETFILTER_XTABLES]
</M> LOG target support [CONFIG_NETFILTER_XT_TARGET_LOG]
IP: Netfilter Configuration —>
<*/M> IP tables support (required for filtering/masq/NAT) [CONFIG_IP_NF_IPTABLES]
1.第一个问题
can’t initialize iptables table `nat’
在网上试了N种方法无效,突然想起来有没有可能内核没有配置
将CONFIG_NF_NAT改成Y
顺带这把iptables相关的全改了
后续解冲突,基本需要编译的文件都在ipv4文件夹下和netfilter文件夹下
2.第二个问题
nat问题解决完,又出现新的BUG
MASQUERADE Target not found
1.iptables所有东西我都加了,找了一份安卓的kernel看,发现有一个ipt_MASQUERADE.c的文件.
2.移过来,解不完的冲突,放弃.
3.检查了一下kernel的版本,发现一个是4.x,一个是5.x
4.在网上下了几份5.x的,发现都没有ipt_MASQUERADE.c,难道命令变化了
5.打开我自己的手机,kernel版本是linux_5.10,尝试把wifi转发到sim卡上去,iptables -t nat -A POSTROUTING -o ccmni0-j MASQUERADE,命令可用
6.既然iptables命令没有变化,肯定是能够支持的MASQUERADE.直接全局搜索
终于在在xt_MASQUERADE.c里找到了
7.最后找了份linux5.X的config,把ip和netfileter的配置copy下来了