- local msg='{"network": "'"$network"'", "prefix": "'"$addr"'", "length": '"$length"
- [ -n "$valid" ] && msg="$msg"', "valid": '"$valid"', "preferred": '"$prefer"
- [ -z "$cmd" ] && cmd=newprefix
-
- ubus call 6distributed "$cmd" "$msg}"
+ # Get prefix configuration
+ local ula=""
+ local prefix_action=""
+ config_get ula global ula_prefix
+ config_get prefix_action "$network" prefix_action
+ [ -z "$prefix_action" ] && prefix_action="distribute"
+
+ # Always announce the ULA when doing NPT
+ [ "$prefix" == "$ula" -a "$prefix_action" == "npt" ] && prefix_action="distribute"
+
+ [ "$prefix_action" == "distribute" -o "$prefix_action" == "npt" ] && {
+ local msg='{"network": "'"$network"'", "prefix": "'"$addr"'", "length": '"$length"
+ [ -n "$valid" ] && msg="$msg"', "valid": '"$valid"', "preferred": '"$prefer"
+ [ -z "$cmd" ] && cmd=newprefix
+
+ [ "$prefix_action" == "npt" ] && msg="$msg"', "npt": 1'
+ [ "$type" == "secondary" ] && msg="$msg"', "secondary": 1'
+
+ # Detect MTU
+ local mtu
+ conf_get mtu "$device" mtu
+ msg="$msg"', "mtu": '"$mtu"
+
+ ubus call 6distributed "$cmd" "$msg}"
+ }
+
+ [ "$prefix_action" == "npt" ] && {
+ local chain="network6_npt_$network"
+ local ula_addr=$(echo "$ula" | cut -d/ -f1)
+ local ula_rem=$(echo "$ula" | cut -d/ -f2)
+ local ula_length=$(echo "$ula_rem" | cut -d, -f1)
+ local device=""
+
+ network_get_device device "$network"
+ [ "$length" -lt "$ula_length" ] && length="$ula_length"
+ [ "$cmd" == "delprefix" ] && cmd="-D $chain" || cmd="-A $chain"
+
+ local in="-i $device -d $addr/$length -j NETMAP --to $ula_addr/$ula_length"
+ local out="-o $device -s $ula_addr/$ula_length -j NETMAP --to $addr/$length"
+
+ setup_npt_chain start "$network"
+ $NAT $cmd $in
+ $NAT $cmd $out
+ }