Reintroduce the IP rule&route for OAI UE through setup_ue_ipv4_route()

These rules & route are necessary to properly send packets on oaitun_ue1
interface:

1. This forces the packets coming from a subnet different than the UE's
   subnet to go back through oaitun_ue1 rather than via what the default
   route defined on the system (e.g., important if ping from the
   internet arrives).

2. On machines setting net.ipv4.conf.oaitun_ue1.rp_filter=1 (e.g.
   RHEL), this prevents that source filtering for packets coming back is
   applied and those packets be dropped. By default, many hosts have
   rp_filter=2, so no strict source filtering is applied, and it would
   work; on others, this rule prevents source filter dropping.
This commit is contained in:
Robert Schmidt
2024-08-02 15:29:36 +02:00
parent 2da09aba80
commit ffcf53fc75
4 changed files with 44 additions and 0 deletions
+27
View File
@@ -29,6 +29,7 @@
#include "nas_config.h"
#include "common/utils/LOG/log.h"
#include "common/utils/system.h"
/*
* \brief set a genneric interface parameter
@@ -107,3 +108,29 @@ bool nas_config(int interface_id, const char *ip, const char *ifpref)
close(sock_fd);
return success;
}
void setup_ue_ipv4_route(int interface_id, const char *ipv4, const char *ifpref)
{
int table_id = interface_id - 1 + 10000;
char interfaceName[IFNAMSIZ];
snprintf(interfaceName, sizeof(interfaceName), "%s%d", ifpref, interface_id);
char command_line[500];
int res = sprintf(command_line,
"ip rule add from %s/32 table %d && "
"ip rule add to %s/32 table %d && "
"ip route add default dev %s table %d",
ipv4,
table_id,
ipv4,
table_id,
interfaceName,
table_id);
if (res < 0) {
LOG_E(UTIL, "Could not create ip rule/route commands string\n");
return;
}
background_system(command_line);
}
+14
View File
@@ -40,4 +40,18 @@
*/
bool nas_config(int interface_id, const char *ip, const char *ifprefix);
/*!
* \brief Setup a IPv4 rule in table (interface_id - 1 + 10000) and route to
* force packets coming into interface back through it, and workaround
* net.ipv4.conf.all.rp_filter=2 (strict source filtering would filter out
* responses of packets going out through interface to another IP address not
* in same subnet).
* \param[in] interface_id number of this interface, prepended after interface
* name
* \param[in] ipv4 IPv4 address of the UE
* \param[in] ifprefix interface name prefix to which an interface number will
* be appended
*/
void setup_ue_ipv4_route(int interface_id, const char *ipv4, const char *ifpref);
#endif /*NAS_CONFIG_H_*/