nas_config(): provide entire IP address to configure

Prior to this commit, there was a global variable baseNetAddress that
could be set independently through a setter and also through the
configuration module. This baseNetAddress (16 bits IPv4) would then be
complemented with two more bytes in nas_config().

However, this is counter-productive, as not only we have a global
variable that is avoidable (we can give the entire address to
nas_config() directly), but it also would not work with IPv6. Hence,
modify to give nas_config() the entire address. A follow-up commit will
add IPv6 support.
This commit is contained in:
Robert Schmidt
2024-08-02 15:29:36 +02:00
parent 2c878c10ec
commit 2da09aba80
8 changed files with 56 additions and 108 deletions
+5 -7
View File
@@ -2296,28 +2296,26 @@ uint64_t pdcp_module_init( uint64_t pdcp_optmask, int id) {
pdcp_params.optmask = pdcp_params.optmask | pdcp_optmask ;
nas_getparams();
if (UE_NAS_USE_TUN) {
int num_if = (NFAPI_MODE == NFAPI_UE_STUB_PNF || IS_SOFTMODEM_SIML1 || NFAPI_MODE == NFAPI_MODE_STANDALONE_PNF) ? MAX_MOBILES_PER_ENB : 1;
netlink_init_tun("oaitun_ue", num_if, id);
if (IS_SOFTMODEM_NOS1)
nas_config(1, 1, 2, "oaitun_ue");
nas_config(1, "10.0.1.2", "oaitun_ue");
netlink_init_mbms_tun("oaitun_uem", id + 1);
nas_config(1, 2, 2, "oaitun_uem");
nas_config(1, "10.0.2.2", "oaitun_uem");
LOG_I(PDCP, "UE pdcp will use tun interface\n");
} else if (ENB_NAS_USE_TUN) {
netlink_init_tun("oaitun_enb", 1, 0);
nas_config(1, 1, 1, "oaitun_enb");
nas_config(1, "10.0.1.1", "oaitun_enb");
if (pdcp_optmask & ENB_NAS_USE_TUN_W_MBMS_BIT) {
netlink_init_mbms_tun("oaitun_enm", 1);
nas_config(1, 2, 1, "oaitun_enm");
nas_config(1, "10.0.2.1", "oaitun_enm");
LOG_I(PDCP, "ENB pdcp will use mbms tun interface\n");
}
LOG_I(PDCP, "ENB pdcp will use tun interface\n");
} else if (pdcp_optmask & ENB_NAS_USE_TUN_W_MBMS_BIT) {
netlink_init_mbms_tun("oaitun_enm", 0);
nas_config(1, 2, 1, "oaitun_enm");
nas_config(1, "10.0.2.1", "oaitun_enm");
LOG_I(PDCP, "ENB pdcp will use mbms tun interface\n");
}
+3 -4
View File
@@ -610,8 +610,6 @@ uint64_t nr_pdcp_module_init(uint64_t _pdcp_optmask, int id)
pdcp_optmask = pdcp_optmask | _pdcp_optmask ;
nas_getparams();
if (UE_NAS_USE_TUN) {
char *ifprefix = get_softmodem_params()->nsa ? "oaitun_nrue" : "oaitun_ue";
int num_if = (NFAPI_MODE == NFAPI_UE_STUB_PNF || IS_SOFTMODEM_SIML1 || NFAPI_MODE == NFAPI_MODE_STANDALONE_PNF)
@@ -619,7 +617,8 @@ uint64_t nr_pdcp_module_init(uint64_t _pdcp_optmask, int id)
: 1;
netlink_init_tun(ifprefix, num_if, id);
if (IS_SOFTMODEM_NOS1) {
nas_config(1, 1, !get_softmodem_params()->nsa ? 2 : 3, ifprefix);
const char *ip = !get_softmodem_params()->nsa ? "10.0.1.2" : "10.0.1.3";
nas_config(1, ip, ifprefix);
set_qfi_pduid(7, 10);
}
LOG_I(PDCP, "UE pdcp will use tun interface\n");
@@ -627,7 +626,7 @@ uint64_t nr_pdcp_module_init(uint64_t _pdcp_optmask, int id)
} else if (ENB_NAS_USE_TUN) {
char *ifprefix = get_softmodem_params()->nsa ? "oaitun_gnb" : "oaitun_enb";
netlink_init_tun(ifprefix, 1, id);
nas_config(1, 1, 1, ifprefix);
nas_config(1, "10.0.1.1", ifprefix);
LOG_I(PDCP, "ENB pdcp will use tun interface\n");
start_pdcp_tun_enb();
}
+7 -4
View File
@@ -765,10 +765,13 @@ rrc_ue_establish_drb(
ip_addr_offset4 = 1;
LOG_I(OIP,"[UE %d] trying to bring up the OAI interface %d, IP X.Y.%d.%d\n", ue_mod_idP, ip_addr_offset3+ue_mod_idP,
ip_addr_offset3+ue_mod_idP+1,ip_addr_offset4+ue_mod_idP+1);
oip_ifup = nas_config(ip_addr_offset3 + ue_mod_idP + 1, // interface_id
UE_NAS_USE_TUN ? 1 : (ip_addr_offset3 + ue_mod_idP + 1), // third_octet
ip_addr_offset4 + ue_mod_idP + 1, // fourth_octet
"oaitun_oip");
char ip[20];
snprintf(ip,
sizeof(ip),
"10.0.%d.%d",
UE_NAS_USE_TUN ? 1 : (ip_addr_offset3 + ue_mod_idP + 1),
ip_addr_offset4 + ue_mod_idP + 1);
oip_ifup = nas_config(ip_addr_offset3 + ue_mod_idP + 1, ip, "oaitun_oip");
if (oip_ifup == 0 && (!UE_NAS_USE_TUN)) { // interface is up --> send a config the DRB
LOG_I(OIP,"[UE %d] Config the ue net interface %d to send/receive pkt on DRB %ld to/from the protocol stack\n",
+3 -4
View File
@@ -5255,10 +5255,9 @@ rrc_eNB_process_RRCConnectionReconfigurationComplete(
LOG_I(OIP, "[eNB %d] trying to bring up the OAI interface oai%d\n",
ctxt_pP->module_id,
ctxt_pP->module_id);
oip_ifup = nas_config(ctxt_pP->module_id, // interface index
ctxt_pP->module_id + 1, // third octet
ctxt_pP->module_id + 1, // fourth octet
"oaitun_oai");
char ip[20];
snprintf(ip, sizeof(ip), "10.0.%d.%d", ctxt_pP->module_id + 1, ctxt_pP->module_id + 1);
oip_ifup = nas_config(ctxt_pP->module_id, ip, "oaitun_oai");
if (oip_ifup == 0) { // interface is up --> send a config the DRB
module_id_t ue_module_id;
+5 -32
View File
@@ -29,31 +29,6 @@
#include "nas_config.h"
#include "common/utils/LOG/log.h"
#include "common/config/config_userapi.h"
//default values according to the examples,
char *baseNetAddress ;
#define NASHLP_NETPREFIX "<NAS network prefix, two first bytes of network addresses>\n"
void nas_getparams(void) {
// this datamodel require this static because we partially keep data like baseNetAddress (malloc on a global)
// but we loose the opther attributes in nasoptions between two calls if is is not static !
// clang-format off
paramdef_t nasoptions[] = {
/*--------------------------------------------------------------------------------------------------------------------------------------------------------------------*/
/* configuration parameters for netlink, includes network parameters when running in noS1 mode */
/* optname helpstr paramflags XXXptr defXXXval type numelt */
/*--------------------------------------------------------------------------------------------------------------------------------------------------------------------*/
{"NetworkPrefix", NASHLP_NETPREFIX, 0, .strptr=&baseNetAddress, .defstrval="10.0", TYPE_STRING, 0 },
};
// clang-format on
config_get(config_get_if(), nasoptions, sizeofArray(nasoptions), "nas.noS1");
}
void setBaseNetAddress (char *baseAddr) {
strcpy(baseNetAddress,baseAddr);
}
/*
* \brief set a genneric interface parameter
@@ -104,21 +79,19 @@ static bool change_interface_state(int sock_fd, const char *ifn, if_action_t if_
}
// non blocking full configuration of the interface (address, and the two lest octets of the address)
int nas_config(int interface_id, int thirdOctet, int fourthOctet, const char *ifpref)
bool nas_config(int interface_id, const char *ip, const char *ifpref)
{
char ipAddress[20];
char interfaceName[IFNAMSIZ];
sprintf(ipAddress, "%s.%d.%d", baseNetAddress,thirdOctet,fourthOctet);
snprintf(interfaceName, sizeof(interfaceName), "%s%d", ifpref, interface_id);
int sock_fd = socket(AF_INET, SOCK_DGRAM, 0);
if (sock_fd < 0) {
LOG_E(UTIL, "Failed creating socket for interface management: %d, %s\n", errno, strerror(errno));
return 1;
return false;
}
change_interface_state(sock_fd, interfaceName, INTERFACE_DOWN);
bool success = setInterfaceParameter(sock_fd, interfaceName, ipAddress, SIOCSIFADDR);
bool success = setInterfaceParameter(sock_fd, interfaceName, ip, SIOCSIFADDR);
// set the machine network mask
if (success)
success = setInterfaceParameter(sock_fd, interfaceName, "255.255.255.0", SIOCSIFNETMASK);
@@ -127,9 +100,9 @@ int nas_config(int interface_id, int thirdOctet, int fourthOctet, const char *if
success = change_interface_state(sock_fd, interfaceName, INTERFACE_UP);
if (success)
LOG_I(OIP, "Interface %s successfully configured, ip address %s\n", interfaceName, ipAddress);
LOG_I(OIP, "Interface %s successfully configured, ip address %s\n", interfaceName, ip);
else
LOG_E(OIP, "Interface %s couldn't be configured (ip address %s)\n", interfaceName, ipAddress);
LOG_E(OIP, "Interface %s couldn't be configured (ip address %s)\n", interfaceName, ip);
close(sock_fd);
return success;
+8 -27
View File
@@ -19,44 +19,25 @@
* contact@openairinterface.org
*/
/*! \file nas_config.h
* \brief Configures the nasmesh interface
* \author Daniel Camara and navid nikaein
* \date 2006-2011
* \version 0.1
* \company Eurecom
*/
#ifndef NAS_CONFIG_H_
#define NAS_CONFIG_H_
#include <stdbool.h>
#include <netinet/in.h>
/*! \fn void void nas_getparams(void)(void)
* \brief This function get parameters used to configure network interface when running in noS1 mode
* \note
* @ingroup _nas
*/
void nas_getparams(void);
/*! \fn int nas_config(char*, int, int)
* \brief This function initializes the nasmesh interface using the basic values,
* basic address, network mask and broadcast address, as the default configured
* ones
* \param[in] interfaceName, the name of the interface, e.g. nasmesh0 or nasmesh1
* \param[in] third octet of the ip address e.g. for the 10.1.2.3 address would be 2
* \param[in] fourth octet of the ip address e.g. for the 10.1.2.3 address would be 3
* \return 0 on success, otherwise 1, if couldn't open a socket and 2 if the ioctl fails
* \param[in] interface_id number of this interface, prepended after interface
* name
* \param[in] ip IPv4 address of this interface as a string
* \param[in] ifprefix interface name prefix to which an interface number will
* be appended
* \return true on success, otherwise false
* \note
* @ingroup _nas
*/
int nas_config(int interface_id, int thirdOctet, int fourthOctet, const char *ifprefix);
/*! \fn void setBaseNetAddress(char*)
* \brief This function sets the basic network address used
* \param[in] baseAddr, the new basic address e.g.for 10.0.1.2, would be 10.0
* \note
* @ingroup _nas
*/
void setBaseNetAddress(char *baseAddr);
bool nas_config(int interface_id, const char *ip, const char *ifprefix);
#endif /*NAS_CONFIG_H_*/