OpenWrtã§ããªã·ã¼ã«ã¼ãã£ã³ã°ãå
¥ãã
ããªã·ã¼ã«ã¼ãã£ã³ã°ãå
¥ããã¨ä½ãå¬ããã®ãã
OpenWrtã® nftables (nft) ã§ã¯ inet fw4
ã®ãã¼ãã«ã«å
¨é¨å
¥ã£ã¦ããã
ãããLuciã®ZONE転éã®è¨±å¯æå¦ã¨Traffic Acceptããã¾ã両ç«ããã®ã大å¤ã ã£ãã
Zone 転éã¨NAT許å¯è¨å®ã§forwardãã´ãã£ã´ãã£ããããã·ã³ãã«ã«ãããã
OpenWrtã®ZONE転éè¨å®ã¯default ã reject ã§ããã
nft ã§å¥ãã¼ãã«ãä½ã£ã¦acceptã追å ãã¦ããããã©ã«ãã®ãã¼ãã« inet fw4 ã§ZONE転éã«ããããã¦reject ããããã³ãã³ãã§inet fw4 ã® forward ãã§ã¤ã³ã«è¨±å¯ããè¨å®ã追å ã㦠forward ã acceptããã
ããããnft table inet fw4 ãã¼ãã«ã®forward ãã§ã¤ã³è¨è¿°ã大éã«ãªãã追ããããã®ãé¢åã«ãªã諦ããã
ç¹ã«ãforwardãã§ã¤ã³ã«IPã¢ãã¬ã¹ãç´æ¥è¨è¿°ã«ã¼ã«ã大éã«æ¸ãã¦å
¨ä½ãè¦å¤±ãããã±ããçéãã¹ãå¼ãèµ·ããã¾ãã£ãã
ããã§ãforwardãã§ã¤ã³ãã·ã³ãã«å¶å¾¡ããã¾ãããããã®ããã«ãã¼ã¯ã使ã£ãããªã·ã¼ã«ã¼ãã£ã³ã°ãæ´»ç¨ããã
å
¨ä½ã®æ¹é
- nftables 㧠ãã±ããã«ãã¼ã¯ãä»ãã
- openwrt ã®fw4 ã«ãã¼ã¯æ¸ãã±ããã®FowardãAcceptããè¨å®ããããã
- ip rule ã§ãã¼ã¯æ¸ãã±ããç¨ã®ã«ã¼ãã£ã³ã°ãã¼ãã«ãä½ãã
ãã±ããããã¼ã¯ããªãã¦ãç®çã¯éæã§ãããã®ã®ãä¸è¨ã§æ¸ããåé¡ï¼fowardãããµããããï¼ã¨ãããã¨ãããã®ã§ãå®é¨ç¨ã®ãããã¯ã¼ã¯ã¯nftablesã®å¥ãã¼ãã«ã«åãåºããå®ç¾ãããå¥ãã¼ãã«ã§ãã¼ã¯ããè¨å®ãæ¸ãã¦ããã°ãã°ãã£ã°ãã£ã«ãã¦ãå½±é¿ç¯å²ã¯æããããã
ä»åä½ããããã¯ã¼ã¯
ã«ã¼ã¿éã®è»¢éã¨ãã¦ã¯ãããµãã¦ãã
ãã¼ã¯ãããã±ãããå¥ã®GWãæµãããã
ãã ããã¼ã¯ãããã±ããããå¥ã®çµè·¯ã§æµããã¨ãããã¨ã§ããã
nftables ã®å¦çã
ãã®ã¨ããFowardã§Acceptããã®ã¯ãã¼ã¯æ¸ã¿ã®ãã±ããã ãã¨ããã
nftables ã§ã¯ãprerouting ã§æ¡ä»¶ããããããã±ããã«ãã¼ã¯ãä»ãããfowardã§ãã¼ã¯æ¸ãã±ããã®è»¢éãAcceptããã
ã«ã¼ãã£ã³ã°ãã¼ãã«ãFOWARDãã§ã¤ã³ã«ç´°ããæ¡ä»¶ãæ¸ãã¦ããã¨æ°ãå¢ãã¦ãã¾ãç
©éã«ãªãã
ãã®é²æ¢ã®ãããprerouting ã§ä»è¨³å¦çãå
ã«æ¸ã¾ãããã¼ã¯ããã
nft ã®ãã¼ãã«ãåãã¦ç®¡çããã
nftables ã«ã¯ãã§ã¤ã³ãå¥ãã¼ãã«ã«åå²ã§ããã®ã§ãprerouting ãå¥ãã¼ãã«ã«åãã¦ãã¾ãã
ãã±ããããã¼ã¯ããæ¡ä»¶ãå¥ãã¼ãã«ã«ãã¦æ¡ä»¶ã«ç¹åãããã¼ãã«ãç¨æãã¦ãããã ãè¦ã¦ç®¡çããããã«ããã
å®éã®å¦ç
å®éã«ä½ã£ãä½æ¥ã¯æ¬¡ã®ã¨ããã«ãªã
OpenWrt ã§forwardã¸ãã¼ã¯æ¸ã¿Acceptãå
¥ããã
acceptããã«ã¼ã«ã¯ãã·ã³ãã«ã«ãããMARK ããããã±ããã許å¯ããã
MARK=666
FW4='inet fw4'
HANDLE_REJECT=$(nft -a list chain $FW4 forward | grep handle_reject | grep -oP '(?<=handle )+\d+' )
COMMENT=accept_sample
nft insert rule "$FW4" forward position $HANDLE_REJECT \
mark $MARK counter accept comment "\"takuya: ${COMMENT} \""
çµæã確èªããã
> nft list chain inet fw4 forward
table inet fw4 {
chain forward {
type filter hook forward priority filter; policy drop;
## Luci ã§å
¥ããã«ã¼ã«
rule ...
# æ«å°¾ã«è¿½å ããã
meta mark 0x0000029a counter packets 250 bytes 21272 accept comment "takuya: accept_v6_sample "
jump handle_reject
}
}
æ«å°¾(handle_rejectã®ç´å)ã«ãã«ã¼ã«ã追å ãããã
OpenWRT ãä½ãfw4 ã®forwardãã¼ãã«ã¯ãdefault ã DROP ã«ãªã£ã¦ãã¦ãä¸ã¤ãæªãããã¯REJECTã«éãããããã®ããforwardä¸ã«ACCEPTã差込ãå¿
è¦ããã£ãã
ãã±ããããã¼ã¯ããnftãã¼ãã«ãä½ã
ãã¼ãã³ã°ããæ¡ä»¶ãæ¸ãããå°ç¨ãã¼ãã«ãä½ãã
å
ã»ã©ãã¼ã¯ãããã±ããããAcceptãããããã«æ¸ãããããã§ã¯ãæå®æ¡ä»¶ãã±ããããã¼ã¯æ¸ã«ããããã®æ°ããå¥ãã¼ãã«ãä½ãããã®ä¸ã«ãã§ã¤ã³ãä½ã£ãããã§ãã«ã¼ã«ããããã
次ã®ååã§ããã¼ãã«ãä½ã£ã¦prerouting ã®ãã§ã¤ã³ãä½ãã
TABLE='ip6 marking_sample'
nft create table $TABLE
nft create chain "$TBL" prerouting {\
type filter hook prerouting priority filter \; policy accept \; \
}
prerouting 㧠ãã¼ã¯æ¡ä»¶ãä½ãã
TABLE='ip6 marking_sample'
IIF=br-lan
MARK=666
DNET=2404:6800:400a:80b::/64
PC=fd01:b::3/64
nft insert rule $TABLE prerouting \
iifname $IIF ip6 daddr $DNET \
ip6 saddr $PC \
counter meta mark set $MARK
ä»åæ¸ãããµã³ãã«æ¡ä»¶ã¯ãgoogle.com AAAA 2404:6800:400a:80b::200e
(2024-08-16ç¾å¨)ã®ãã±ããã¯ãã¼ã¯ã¨ããã
ãã®è¨è¿°ã§ãããããããã±ããã¯ãã¼ãã³ã°ãããinet fw4 forwardãééããã¨ãã«ããã¼ã¯æ¸ãªã®ã§forward ACCEPTãããã
masquerade ã®è¿½å
ã¾ãããã¼ã¯ããããã±ãããåºã¦ããã¨ãã«masquerade ãã¦ãã
TABLE='ip6 marking_sample'
OIF=wg0
MARK=666
DNET=2404:6800:400a:80b::/64
nft create chain $TABLE postrouting { \
type nat hook postrouting priority filter\; policy accept \; \
}
nft add rule $TABLE postrouting \
oifname $OIF ip6 daddr $DNET counter masquerade
OpenWrtã®å ´åã¯ãZONEè¨å®ã§ãã§ãã¯ããããã¨MASQURADEã¯è¨å
¥ããªãã¦ã大ä¸å¤«ã§ããã念ã®çºã
ip rule ãä½ãï¼ããªã·ã¼ã«ã¼ãã£ã³ã°ï¼
ãã¼ã¯æ¸ãã±ããå°ç¨ã®ã«ã¼ãã£ã³ã°ãå¿
è¦ã
ããã§å°ç¨ã®ã«ã¼ãã£ã³ã°ãã¼ãã«ãä½ãã
MARK=666
GW2=fd00:aaa:afac:1919::1
ip -6 rule del table $MARK >& /dev/null
ip -6 rule add fwmark $MARK table $MARK
ip -6 route add $DNET dev $OIF via $GW2 table $MARK
ã«ã¼ãã£ã³ã°ããã¹ããã
MARK=666
GG=2404:6800:400a:80b::200e
ip -6 route get fibmatch $GG mark $MARK
ä¸è¨ã®fibmatch
ã使ãã¨ããããããrouting ã«ã¼ã«ããã®ã¾ã¾è¡¨ç¤ºãã¦ããã¦ä¾¿å©ãadd ããã«ã¼ã«ããã®ã¾ã¾è¡¨ç¤ºãããã°ãã§ãã¯ã»ãªãã±ã
åé¤ããã¨ãã¯ã次ã®ã³ãã³ãã§
MARK=666
ip -6 rule del table $MARK >& /dev/null
ip -6 route flush table $MARK
ãã¹ã£ããflushãããdeleteããã°è¯ãã
ä»åã¯ãgoogle.com AAAA
ã®v6ã¢ãã¬ã¹ãããµããããæå®ããããã®å®å
ã¢ãã¬ã¹ãDNET='2000::/3'
ã«ãããã¨ã§ãv6ã®ã°ãã¼ãã«IP空éããã¹ã¦ãã«ã¼ãã£ã³ã°å¯¾è±¡ã«ã§ããã¯ãã2000::/3
ã¯::/0
ãdefault
ããããããããããã¨æããããã©ã«ã使ãã¨ãªã³ã¯ãã¼ã«ã«ã¨ããæ··ãã£ã¦é¢åããã
mark ãacceptããã¡ãªããã
ãã©ã¯ã¼ãã»ãã§ã¤ã³ã溢ããã«æ¸ãã ã
nftablesã¯ãjump ã§æ¸ãã¦ããããããããjump jump ã§ããµããããã¨jumpã®jumpã§è¿½è·¡ãç
©éã ã£ããããã¦ãã©ã¯ã¼ãã§ã¸ã£ã³ãããã¨ã管çã OpenWrt ã®Luciçæã®fw4 ã¨æ··å¨ãã¦ãã¾ããOpenwrt ã®ããã©ã«ãã§ããfw4ã¯luci ã®ç»é¢è¨å®ã«ä¾åãããfw4ã«ã³ãã³ãã§è¿½è¨ãã¦ããã¨ãã©ãã§è¿½è¨ãããã®ããã¸ã£ã³ã追跡ãç
©éããããluciç±æ¥ã®fw4ããã¾ãã´ãã£ã´ãã£ãããããªãã
ã¾ããã«ã¼ããå¤ãããã¨ãã«ãå°ç¨ã®ãã¼ãã«ã触ãã ãã§æ¸ãããä¸æçã«æ¢ããããã°ããã¼ã¯ä»ä¸ãã¼ãã«ãdelete ããã°æ¸ãã®ãå¬ããã
æ´ã«nft ã¯handleã使ãã®ãé¢åãjump ã§ã«ã¼ã«ãæ¸ããããdelete add ããããadd flag dormant ã¨ãããã¡ãã£ã¨ããä½æ¥ã«æ¯åå¤ããHANDLEãæ¢ãã®ãæéã§ä»æ¹ãªããä»åç¨ã«ãã¼ã¯ãã¤ãããã¼ãã«æ¶ãã»ãã¼ãã«ä½ãã§ä»£ç¨ããã¨éã³ããããªã£ãã
ãããããã¨ã§ãnft ã®HANDLEã使ããã«ããã¼ã¯ãã¤ãããã¨ã«ãããè¦ãã¹ãç®æãOpenWrtããåãé¢ããå¥ãã¼ãã«ï¼ãã¼ã¯ãä»ãããã¼ãã«ï¼ã«éå®ã§ãã¦ç®¡çãã ãã¶æ¥½ã«ãªãã¾ããã
v6 NAT
ä»åã®ä¾ã¯ãv6 㧠NAT66 ããä¾ã«ãªãã®ã ãã©ãv6 ã§NATãããæå³ãªãã£ã¦æããããããªããã©ãv6 NATã使ããã¨å²ã¨ä¾¿å©ãªãã§ãããã
ãIPv6ã§ã¯NATãããªãï¼ä¸è¦ï¼ããªã©ã¨æç§æ¸ã«ã¯æ¸ãã¦ããã©ãNATãã£ãã»ãã絶対便å©ã好ããªIPoEã®æ¥ç¶ç¹ãåºå£ã«æ®ãã¦ãä»»æISPããåºã¦åç·ãã¹ããããããããã£ã±ãv6 NATã¯ã¢ãªãããªãããªã
ã»ãã¥ãªãã£ã«ã¤ãã¦ãNATã¯é²æ³¢å ¤ã«ãªãå¾ãæ°ããããã°ãã¼ãã«IPv6ã§éä¿¡ããv6ã¯ãOSã®ãã¡ã¤ã¢ã¦ã©ã¼ã«æ©è½ã«ä¾åããããã§ãOSã«èå¼±æ§ãã¤ã¾ãLinuxã®nftablesãWindowsãã¡ã¤ã¢ã¦ã©ã¼ã«ã«èå¼±æ§ããã£ãå ´åã¯ã大äºæ
ã«ãªãã¨æããã§ãããã¾ãã¦ã¼ã¶ã¼ãã³ããã§å®æãªè¨±å¯è¨å®ããã¦ãã¾ãå¯è½æ§ãæãã
NAT66ããã¹ãã ã¨æãçç±ã«ã¼ããã¤æ»æãããã
ã°ãã¼ãã«IPãå²ãå½ã¦ããã¦ããã¨ãOSã®èå¼±æ§ã®å½±é¿ãããã«åããã
OSã®FWã«èå¼±æ§ãããã¨ãã°ãã¼ãã«IPãå²ããã£ã¦ãããã¹ã¦ã®ç«¯æ«ã«å½±é¿ãåºãã
ããæã£ã¦ããã®ã ããåºã¦ãã¾ã£ããåºã¦ãã¾ã£ãã®ã§ããèå¼±æ§ã
CVE-2024-38063
ã§Windowsã®TCP/IPã®ã¹ã¿ãã¯èå¼±æ§ã§ãªã¢ã¼ãã³ã¼ãã®å®è¡ãããã¼ããã¤çºè¦ãã¦ããã
ãããã§ãã¾ã§v6 ãªãã«ããã¬ãã«ãã£ã¦ãã¤ã§ãã
ç·æ¥ãããã¯ã§ããã®ã®ã»ã»ã»ãã£ã±ããNAT66ã§NATããããªãã£ã¦èãã¾ããã端æ«ã®IPã管çããã«ãã¦ãULAã®ã»ããä½ãã¨æ¥½ããã»ã»ã»
TCPãªã®ã§FWã§CONNECTEDãè¦ã¦ãã°å¤§ä¸å¤«ãªã¯ãã§ã¯ãããv6é¢é£ã®ãã§ãã¯ãçãã¦state new ãéã£ã¡ãã£ãããã¦ãªãã§ãããã
ä»åã¯v6 NAT ã¨ããªã·ã¼ã«ã¼ãã£ã³ã°ã§æå®PCã®GWãå¤ããã
ä»åã¯ãOpenWrtã®fw4 ãLuciã使ããã«ãæå®PCãæå®ãµããããã ãã¯ãv6 空éã«åºãããããã«ããè¨å®ã試ãã¦ã¿ãã
wireguardãStrongswanã®ãããªVPNã¨çµã¿åããã¦ã好ããªç®æããv6ã¢ãã¬ã¹åºã¦ããããè¨å®ãã·ã³ãã«ã«ããç®å¦ããã£ã
Linuxç®±ãã«ã¼ã¿ã«ãã¦ããã¨ã¡ãã£ã¨ããæãã¤ãã試ãã¦è¯ããã