How to start 464xlat by manual cmd

Describe:
1.Try uci config 464xlat as follows:

#1.Config WAN
uci set network.wan=interface
uci set network.wan.ifname='ccmm0'
uci set network.wan.proto='dhcp'

#2.Config 464XLAT
uci set network.xlatd=interface
uci set network.xlatd.proto='464xlat'
uci set network.xlatd.tunlink='wan'
uci set network.xlatd.ip6prefix='64:ff9b::/96'
uci commit network

#Enable 464xlat
ifup wan
ifup xlatd

Result: new interface 464xlat OK.

2.Try manual cmd enable 464xlat.
Ref script /lib/netifd/proto/464xlat.sh:
464xlat: import from routing, add myself as maintainer ยท 633cac0cb4 - openwrt - Gitce

#ip6addr=$(464xlatcfg "$link" "$tundev" "$ip6prefix" 192.0.0.1 $ip6addr)
#link: new 464xlat interface name
#tundev: as uci 'wan' real l3.interface ccmm0
#ip6prefix: as uci config "64:ff9b::/96"
#ip6addr: set NULL
ip6addr=`464xlatcfg 464xlat ccmm0 64:ff9b::/96 192.0.0.1` #OK, get a ipv6 address
ip -6 rule del from all lookup local
ip -6 rule add from all lookup local pref 1
ip -6 rule add to $ip6addr lookup prelocal pref 0

Result: fail.

My Question:
1.How to add 464xlat by manual cmd?
2.Because ccmm0 is SIM data. Our system configed by background program.
So now not "wan uci config".
Do you have other ways or suggestion?

Thanks.

From code:
openwrt/package/network/ipv6/464xlat/src/464xlatcfg.c

	FILE *nat46 = fopen("/proc/net/nat46/control", "w");
	if (!nat46 || fprintf(nat46, "add %s\nconfig %s local.style NONE local.v4 %s/32 local.v6 %s/128 "
			"remote.style RFC6052 remote.v6 %s\n", argv[1], argv[1], argv[4], buf, prefix) < 0 ||
			fclose(nat46))
		return 4;

	if (!(pid = fork())) {
		fclose(fp);
		fclose(stdin);
		fclose(stdout);
		fclose(stderr);
		chdir("/");
		setsid();
		signal(SIGTERM, sighandler);  //Q1: This netifd send SIGTERM del 464xlat interface.
		pause();
	
		nat46 = fopen("/proc/net/nat46/control", "w");
		if (nat46) {
			fprintf(nat46, "del %s\n", argv[1]);
			fclose(nat46);
		}
	} else {
		rewind(fp);	
		fprintf(fp, "%d\n", pid);
	}

Q2:
Check nat46 proc, as follows:
cat /proc/net/nat46/control

add 464-clatd
config 464-clatd local.v4 192.0.0.1/32 local.v6 240e:47c:30d0:c18:cc10:f57:d1d0:f572/128 local.style NONE local.ea-len 0 local.psid-offset 0 remote.v4 0.0.0.0/0 remot
e.v6 64:ff9b::/96 remote.style RFC6052 remote.ea-len 0 remote.psid-offset 0 debug 0

But not create nat46 interface.

Now status:
Try modify script: /lib/netifd/proto/464xlat.sh

--#network_get_device tundev $tunlink
++tundev="ccmm0" 

Manual send ubus msg as follows:

ubus call network.interface notify_proto '{ "action": 0, "ifname": "464-clatd", "link-up": true, "data": { "firewall": [ { "type": "nat", "target": "SNAT", "family": "inet", "snat_ip": "192.0.0.1" } ] }, "keep": false, "routes": [ { "target": "0.0.0.0", "netmask": "0", "metric": 2048 } ], "routes6": [ { "target": "240e:47c:3028:d00f:d1cd:9502:1866:a65", "netmask": "128", "table": "128" } ], "interface": "clatd" }'

Result: OK, create 464-clatd link.

464-clatd Link encap:UNSPEC  HWaddr 00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00
          inet6 addr: fe80::bc4f:c9db:3173:87d/64 Scope:Link
          UP POINTOPOINT RUNNING NOARP  MTU:16384  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)

But access internet failed. Check /tmp/resolv.conf is empty.

Next step:
Learning function "network.interface notify_proto" implementation method.
Fix Internet failure, dns , nat firewall.


2022.03.03 update:
Not find notify_proto hooks callback.

I'am failed that start 464xlat by manual cmd.

Follow is my modify. Change tundev

--- a/openwrt/package/network/ipv6/464xlat/files/464xlat.sh
+++ b/openwrt/package/network/ipv6/464xlat/files/464xlat.sh
@@ -12,6 +12,7 @@
 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 # GNU General Public License for more details.

+retFile="/tmp/nat464xlat.log"
 [ -n "$INCLUDE_ONLY" ] || {
        . /lib/functions.sh
        . /lib/functions/network.sh
@@ -29,15 +30,20 @@ proto_464xlat_setup() {

        [ "$zone" = "-" ] && zone=""

-       ( proto_add_host_dependency "$cfg" "::" "$tunlink" )
+       #( proto_add_host_dependency "$cfg" "::" "$tunlink" )

        if [ -z "$tunlink" ] && ! network_find_wan6 tunlink; then
+               echo "12.1 NO_WAN_LINK" >> $retFile
+               sleep 1
                proto_notify_error "$cfg" "NO_WAN_LINK"
                return
        fi
-       network_get_device tundev "$tunlink"

+       #network_get_device tundev "$tunlink"
+       tundev=$(uci get network.clatd.tunlink)
+
+       echo "cmd=464xlatcfg "$link" "$tundev" "$ip6prefix" 192.0.0.1 $ip6addr" >> $retFile
        ip6addr=$(464xlatcfg "$link" "$tundev" "$ip6prefix" 192.0.0.1 $ip6addr)
+       echo "ret=$?, ip6addr=$ip6addr" >> $retFile
        if [ -z "$ip6addr" ]; then
                proto_notify_error "$cfg" "CLAT_CONFIG_FAILED"
                return

Result.
1.ifup clatd
create interface 464-clatd. --OK

2.Manual add

/tmp/resolv.conf
ip ro add default dev 464-clatd proto metric 50
iptables -t nat -D POSTROUTING -o 464-clatd -j SNAT --to-source  192.0.0.1

This cmd you can add in 464xlat.sh steup.

My Question.
464xlat.sh "network.interface notify_proto" implementation method.

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.