ANDROID: ipv6: add vendor hook for gen ipv6 link-local addr

This patch provides an ipv6 vendor hook which can be used to
disable kernel auto generate the ipv6 link-local address.

The reasons why the kernel does not need to automatically
generate the ipv6 link-local address are as follows:

(1) In the 3GPP TS 29.061, here is a description as follows:
"in order to avoid any conflict between the link-local address
of the MS and that of the GGSN, the Interface-Identifier used
by the MS to build its link-local address shall be assigned by
the GGSN. The GGSN ensures the uniqueness of this Interface-
Identifier. The MT shall then enforce the use of this
Interface-Identifier by the TE"

In other words, in the cellular network, GGSN determines whether
to reply a solicited RA message by identifying the low 64 bits
of the source address of the received RS message. Therefore,
cellular network device's ipv6 link-local address should be set
as the format of fe80::(GGSN assigned IID).

For example: When using a new kernel and ARPHRD_RAWIP, kernel
will generate an EUI64 format ipv6 link-local address, and the
Linux kernel will uses this link-local address to send RS message.
The result is that the GGSN will not reply to the RS message with
a solicited RA message.

For mobile operators that don't need to support RFC7217, setting
addr_gen_mode == 1 is sufficient, it can avoid the above issue,
but when the addr_gen_mode is changed to the
IN6_ADDR_GEN_MODE_STABLE_PRIVACY, the above problem still exist.
The detail as follows:

(2) For some other mobile operators that need to support RFC7217,
the mobile device's addr_gen_mode will be switched to the
IN6_ADDR_GEN_MODE_STABLE_PRIVACY, instead of using
IN6_ADDR_GEN_MODE_NONE.
The purpose is: in the IN6_ADDR_GEN_MODE_STABLE_PRIVACY mode,
kernel can gererate a stable privacy global ipv6 address after
receiveing RA, and network processes can use this global address
to communicate with the outside network.

Of course, mobile operators that need to support RFC7217 should
also meet the requirement of 3GPP TS 29.061, that is, MT should
use IID assigned by the GGSN to build its ipv6 link-local address
and use this address to send RS. We don't want the kernel to
automatically generate an ipv6 link-local address when
addr_gen_mode == 2. Otherwise, using the stable privacy ipv6
link-local address automatically generated by the kernel to send
RS message, GGSN will not be able to respond to the RS and reply
a RA message.

Therefore, after this patch, the kernel can determine whether to
disable the automatic ipv6 link-local address generation by judging
the net device name.

Bug: 190685002
Change-Id: I93420cacd96789769edc7214fb8a2dd1455ce374
Signed-off-by: Rocco Yue <rocco.yue@mediatek.com>
This commit is contained in:
Rocco Yue
2021-07-11 13:49:50 +08:00
committed by Greg Kroah-Hartman
parent 018332e871
commit dcf509fea7
3 changed files with 31 additions and 0 deletions

View File

@@ -68,6 +68,7 @@
#include <trace/hooks/net.h>
#include <trace/hooks/syscall_check.h>
#include <trace/hooks/usb.h>
#include <trace/hooks/ipv6.h>
/*
* Export tracepoints that act as a bare tracehook (ie: have no trace event
@@ -353,3 +354,4 @@ EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_check_file_open);
EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_check_bpf_syscall);
EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_usb_dev_suspend);
EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_usb_dev_resume);
EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_ipv6_gen_linklocal_addr);

View File

@@ -0,0 +1,22 @@
/* SPDX-License-Identifier: GPL-2.0 */
#undef TRACE_SYSTEM
#define TRACE_SYSTEM ipv6
#define TRACE_INCLUDE_PATH trace/hooks
#if !defined(_TRACE_HOOK_IPV6_H) || defined(TRACE_HEADER_MULTI_READ)
#define _TRACE_HOOK_IPV6_H
#include <linux/tracepoint.h>
#include <trace/hooks/vendor_hooks.h>
/*
* Following tracepoints are not exported in tracefs and provide a
* mechanism for vendor modules to hook and extend functionality
*/
DECLARE_HOOK(android_vh_ipv6_gen_linklocal_addr,
TP_PROTO(struct net_device *dev, bool *ret),
TP_ARGS(dev, ret));
/* macro versions of hooks are no longer required */
#endif /* _TRACE_HOOK_IPV6_H */
/* This part must be outside protection */
#include <trace/define_trace.h>

View File

@@ -90,6 +90,8 @@
#include <linux/seq_file.h>
#include <linux/export.h>
#include <trace/hooks/ipv6.h>
#define INFINITY_LIFE_TIME 0xFFFFFFFF
#define IPV6_MAX_STRLEN \
@@ -3344,6 +3346,7 @@ static void addrconf_addr_gen(struct inet6_dev *idev, bool prefix_route)
static void addrconf_dev_config(struct net_device *dev)
{
struct inet6_dev *idev;
bool ret = false;
ASSERT_RTNL();
@@ -3371,6 +3374,10 @@ static void addrconf_dev_config(struct net_device *dev)
if (IS_ERR(idev))
return;
trace_android_vh_ipv6_gen_linklocal_addr(dev, &ret);
if (ret)
return;
/* this device type has no EUI support */
if (dev->type == ARPHRD_NONE &&
idev->cnf.addr_gen_mode == IN6_ADDR_GEN_MODE_EUI64)