From 3a125c66d28ab05d20f51d0279db3221976bcfc4 Mon Sep 17 00:00:00 2001 From: Jonathan Hui Date: Thu, 5 May 2022 21:42:58 -0700 Subject: [PATCH] [cli] add command to set mesh-local prefix (#7663) Also add an expect test for getting/setting mesh-local prefix. --- src/cli/README.md | 9 +++++++++ src/cli/cli.cpp | 14 +++++++++++++- tests/scripts/expect/cli-misc.exp | 7 +++++++ 3 files changed, 29 insertions(+), 1 deletion(-) diff --git a/src/cli/README.md b/src/cli/README.md index b2c4056cd..1dd92e45a 100644 --- a/src/cli/README.md +++ b/src/cli/README.md @@ -2177,6 +2177,15 @@ fdde:ad00:beef:0::/64 Done ``` +### prefix meshlocal + +Set the mesh local prefix. + +```bash +> prefix meshlocal fdde:ad00:beef:0::/64 +Done +``` + ### prefix remove \ Invalidate a prefix in the Network Data. diff --git a/src/cli/cli.cpp b/src/cli/cli.cpp index 8ebfa47fb..ef5376ff3 100644 --- a/src/cli/cli.cpp +++ b/src/cli/cli.cpp @@ -3564,7 +3564,19 @@ template <> otError Interpreter::Process(Arg aArgs[]) } else if (aArgs[0] == "meshlocal") { - OutputIp6PrefixLine(*otThreadGetMeshLocalPrefix(GetInstancePtr())); + if (aArgs[1].IsEmpty()) + { + OutputIp6PrefixLine(*otThreadGetMeshLocalPrefix(GetInstancePtr())); + } + else + { + otIp6Prefix prefix; + + SuccessOrExit(error = aArgs[1].ParseAsIp6Prefix(prefix)); + VerifyOrExit(prefix.mLength == OT_IP6_PREFIX_BITSIZE, error = OT_ERROR_INVALID_ARGS); + error = + otThreadSetMeshLocalPrefix(GetInstancePtr(), reinterpret_cast(&prefix.mPrefix)); + } } else { diff --git a/tests/scripts/expect/cli-misc.exp b/tests/scripts/expect/cli-misc.exp index 89da8075e..8b8b4d5ee 100755 --- a/tests/scripts/expect/cli-misc.exp +++ b/tests/scripts/expect/cli-misc.exp @@ -180,6 +180,13 @@ expect "Done" send "ba state\n" expect "Done" +send "prefix meshlocal fd00:dead:beef:cafe::/96\n" +expect_line "Error 7: InvalidArgs" +send "prefix meshlocal fd00:dead:beef:cafe::/64\n" +expect_line "Done" +send "prefix meshlocal\n" +expect_line "fd00:dead:beef:cafe::/64" + send "invalidcommand\n" expect_line "Error 35: InvalidCommand"