From 6374ea11c4e706d585a369c9f069e41e0e0b792e Mon Sep 17 00:00:00 2001
From: Haruue <i@haruue.moe>
Date: Sat, 23 Mar 2024 11:13:43 +0800
Subject: [PATCH] feat(tun): allow omit pfxlen in full len pfx route

---
 app/cmd/client.go | 20 +++++++++++++++-----
 1 file changed, 15 insertions(+), 5 deletions(-)

diff --git a/app/cmd/client.go b/app/cmd/client.go
index ce7b2ba..e3cf756 100644
--- a/app/cmd/client.go
+++ b/app/cmd/client.go
@@ -727,12 +727,22 @@ func clientTUN(config tunConfig, c client.Client) error {
 		server.AutoRoute = true
 		server.StructRoute = config.Route.Strict
 
-		parsePrefixes := func(field string, s []string) ([]netip.Prefix, error) {
+		parsePrefixes := func(field string, ss []string) ([]netip.Prefix, error) {
 			var prefixes []netip.Prefix
-			for i, s := range s {
-				p, err := netip.ParsePrefix(s)
-				if err != nil {
-					return nil, configError{Field: fmt.Sprintf("%s[%d]", field, i), Err: err}
+			for i, s := range ss {
+				var p netip.Prefix
+				if strings.Contains(s, "/") {
+					var err error
+					p, err = netip.ParsePrefix(s)
+					if err != nil {
+						return nil, configError{Field: fmt.Sprintf("%s[%d]", field, i), Err: err}
+					}
+				} else {
+					pa, err := netip.ParseAddr(s)
+					if err != nil {
+						return nil, configError{Field: fmt.Sprintf("%s[%d]", field, i), Err: err}
+					}
+					p = netip.PrefixFrom(pa, pa.BitLen())
 				}
 				prefixes = append(prefixes, p)
 			}