Development discussion of WireGuard
 help / color / mirror / Atom feed
* [PATCH] wg-quick: Android: Use ip link to set MTU
@ 2021-01-03  5:59 Adam Irr
  2021-01-04 17:53 ` Harsh Shandilya
  0 siblings, 1 reply; 3+ messages in thread
From: Adam Irr @ 2021-01-03  5:59 UTC (permalink / raw)
  To: wireguard

[-- Attachment #1: Type: text/plain, Size: 1322 bytes --]

The ndc command used didn't work on my Nvidia Shield (rooted with a custom-built kernel). The ip link command does work. I have only tested this on an Nvidia Shield (Android TV - Version 9.0 Pie).

I couldn't find a lot of documentation on ndc so it's possible my device/kernel is misconfigured. If you suspect this is the case, let me know.

Signed-off-by: Adam Irr <adam.irr@outlook.com>
---
 src/wg-quick/android.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/src/wg-quick/android.c b/src/wg-quick/android.c
index 326efa9..941c7b8 100644
--- a/src/wg-quick/android.c
+++ b/src/wg-quick/android.c
@@ -995,7 +995,7 @@ static void set_mtu(const char *iface, unsigned int mtu)
        int endpoint_mtu, next_mtu;
 
        if (mtu) {
-               cndc("interface setmtu %s %u", iface, mtu);
+               cmd("ip link set dev %s mtu %d", iface, mtu);
                return;
        }
 
@@ -1016,7 +1016,7 @@ static void set_mtu(const char *iface, unsigned int mtu)
                        endpoint_mtu = next_mtu;
        }
 
-       cndc("interface setmtu %s %d", iface, endpoint_mtu - 80);
+       cmd("ip link set dev %s mtu %d", iface, endpoint_mtu - 80);
 }
 
 static void add_route(const char *iface, unsigned int netid, const char *route)
-- 
2.25.1

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-wg-quick-Android-Use-ip-link-to-set-MTU.patch --]
[-- Type: text/x-patch; name="0001-wg-quick-Android-Use-ip-link-to-set-MTU.patch", Size: 1058 bytes --]

From 1ffa6e6318dbeeaaaf56a916bbaa4994df89b599 Mon Sep 17 00:00:00 2001
From: Adam Irr <adam.irr@outlook.com>
Date: Sat, 2 Jan 2021 21:36:12 -0800
Subject: [PATCH] wg-quick: Android: Use ip link to set MTU

Signed-off-by: Adam Irr <adam.irr@outlook.com>
---
 src/wg-quick/android.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/src/wg-quick/android.c b/src/wg-quick/android.c
index 326efa9..941c7b8 100644
--- a/src/wg-quick/android.c
+++ b/src/wg-quick/android.c
@@ -995,7 +995,7 @@ static void set_mtu(const char *iface, unsigned int mtu)
 	int endpoint_mtu, next_mtu;
 
 	if (mtu) {
-		cndc("interface setmtu %s %u", iface, mtu);
+		cmd("ip link set dev %s mtu %d", iface, mtu);
 		return;
 	}
 
@@ -1016,7 +1016,7 @@ static void set_mtu(const char *iface, unsigned int mtu)
 			endpoint_mtu = next_mtu;
 	}
 
-	cndc("interface setmtu %s %d", iface, endpoint_mtu - 80);
+	cmd("ip link set dev %s mtu %d", iface, endpoint_mtu - 80);
 }
 
 static void add_route(const char *iface, unsigned int netid, const char *route)
-- 
2.25.1


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] wg-quick: Android: Use ip link to set MTU
  2021-01-03  5:59 [PATCH] wg-quick: Android: Use ip link to set MTU Adam Irr
@ 2021-01-04 17:53 ` Harsh Shandilya
  2021-01-05  5:50   ` Adam Irr
  0 siblings, 1 reply; 3+ messages in thread
From: Harsh Shandilya @ 2021-01-04 17:53 UTC (permalink / raw)
  To: Adam Irr, Jason; +Cc: wireguard

Hey Adam,

On 2021-01-03 05:59, Adam Irr wrote:
> The ndc command used didn't work on my Nvidia Shield (rooted with a
> custom-built kernel). The ip link command does work. I have only
> tested this on an Nvidia Shield (Android TV - Version 9.0 Pie).
> 
> I couldn't find a lot of documentation on ndc so it's possible my
> device/kernel is misconfigured. If you suspect this is the case, let
> me know.

You couldn't find documentation because there isn't any, it's 
effectively "private API" and Google has broken it time and again. It is 
rather curious that you're running into this issue though, since we've 
had the NDC code in place since before Android 9 came out and went 
through breaking changes in every cycle without these specific 
invocations failing. The last ndc related problem we had was with the 
Android 11 release, where a similar fix[1] was implemented.

I've Cc'ed Jason for reviewing this change, but I'm decidedly curious as 
to why just the Nvidia SHIELD seems to need it.

> 
> Signed-off-by: Adam Irr <adam.irr@outlook.com>
> ---
>  src/wg-quick/android.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/src/wg-quick/android.c b/src/wg-quick/android.c
> index 326efa9..941c7b8 100644
> --- a/src/wg-quick/android.c
> +++ b/src/wg-quick/android.c
> @@ -995,7 +995,7 @@ static void set_mtu(const char *iface, unsigned int 
> mtu)
>         int endpoint_mtu, next_mtu;
> 
>         if (mtu) {
> -               cndc("interface setmtu %s %u", iface, mtu);
> +               cmd("ip link set dev %s mtu %d", iface, mtu);
>                 return;
>         }
> 
> @@ -1016,7 +1016,7 @@ static void set_mtu(const char *iface, unsigned 
> int mtu)
>                         endpoint_mtu = next_mtu;
>         }
> 
> -       cndc("interface setmtu %s %d", iface, endpoint_mtu - 80);
> +       cmd("ip link set dev %s mtu %d", iface, endpoint_mtu - 80);
>  }
> 
>  static void add_route(const char *iface, unsigned int netid, const 
> char *route)
> --
> 2.25.1

Cheers,
Harsh

1: 
https://git.zx2c4.com/wireguard-tools/commit/?id=9a0d65e2afbd6e418c883e0de8555b4fac29f1d5

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] wg-quick: Android: Use ip link to set MTU
  2021-01-04 17:53 ` Harsh Shandilya
@ 2021-01-05  5:50   ` Adam Irr
  0 siblings, 0 replies; 3+ messages in thread
From: Adam Irr @ 2021-01-05  5:50 UTC (permalink / raw)
  To: Harsh Shandilya, Jason; +Cc: wireguard

Hello Harsh,


On 1/4/21 9:53 AM, Harsh Shandilya wrote:
> Hey Adam,
>
> On 2021-01-03 05:59, Adam Irr wrote:
>> The ndc command used didn't work on my Nvidia Shield (rooted with a
>> custom-built kernel). The ip link command does work. I have only
>> tested this on an Nvidia Shield (Android TV - Version 9.0 Pie).
>>
>> I couldn't find a lot of documentation on ndc so it's possible my
>> device/kernel is misconfigured. If you suspect this is the case, let
>> me know.
>
> You couldn't find documentation because there isn't any, it's 
> effectively "private API" and Google has broken it time and again. It 
> is rather curious that you're running into this issue though, since 
> we've had the NDC code in place since before Android 9 came out and 
> went through breaking changes in every cycle without these specific 
> invocations failing. The last ndc related problem we had was with the 
> Android 11 release, where a similar fix[1] was implemented.
>
> I've Cc'ed Jason for reviewing this change, but I'm decidedly curious 
> as to why just the Nvidia SHIELD seems to need it.
>
I get a permission denied error when running the ndc command, even with 
root. Given the lack of ndc documentation I didn't get any further than 
that. If you have any other ideas I can try them.

darcy:/ # ndc interface setmtu wg0 1418
400 0 Failed to set MTU (Permission denied)
darcy:/ # ifconfig wg0 | grep MTU
           UP POINTOPOINT RUNNING NOARP  MTU:1420  Metric:1
darcy:/ # ip link set dev wg0 mtu 1419
darcy:/ # ifconfig wg0 | grep MTU
           UP POINTOPOINT RUNNING NOARP  MTU:1419  Metric:1
darcy:/ # whoami
root


I'll await Jason's review


>>
>> Signed-off-by: Adam Irr <adam.irr@outlook.com>
>> ---
>>  src/wg-quick/android.c | 4 ++--
>>  1 file changed, 2 insertions(+), 2 deletions(-)
>>
>> diff --git a/src/wg-quick/android.c b/src/wg-quick/android.c
>> index 326efa9..941c7b8 100644
>> --- a/src/wg-quick/android.c
>> +++ b/src/wg-quick/android.c
>> @@ -995,7 +995,7 @@ static void set_mtu(const char *iface, unsigned 
>> int mtu)
>>         int endpoint_mtu, next_mtu;
>>
>>         if (mtu) {
>> -               cndc("interface setmtu %s %u", iface, mtu);
>> +               cmd("ip link set dev %s mtu %d", iface, mtu);
>>                 return;
>>         }
>>
>> @@ -1016,7 +1016,7 @@ static void set_mtu(const char *iface, unsigned 
>> int mtu)
>>                         endpoint_mtu = next_mtu;
>>         }
>>
>> -       cndc("interface setmtu %s %d", iface, endpoint_mtu - 80);
>> +       cmd("ip link set dev %s mtu %d", iface, endpoint_mtu - 80);
>>  }
>>
>>  static void add_route(const char *iface, unsigned int netid, const 
>> char *route)
>> -- 
>> 2.25.1
>
> Cheers,
> Harsh
>
> 1: 
> https://git.zx2c4.com/wireguard-tools/commit/?id=9a0d65e2afbd6e418c883e0de8555b4fac29f1d5


Thank you,

Adam


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2021-01-05  5:50 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-01-03  5:59 [PATCH] wg-quick: Android: Use ip link to set MTU Adam Irr
2021-01-04 17:53 ` Harsh Shandilya
2021-01-05  5:50   ` Adam Irr

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).