Commit 2da09aba authored by Robert Schmidt's avatar Robert Schmidt

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.
parent 2c878c10
...@@ -2296,28 +2296,26 @@ uint64_t pdcp_module_init( uint64_t pdcp_optmask, int id) { ...@@ -2296,28 +2296,26 @@ uint64_t pdcp_module_init( uint64_t pdcp_optmask, int id) {
pdcp_params.optmask = pdcp_params.optmask | pdcp_optmask ; pdcp_params.optmask = pdcp_params.optmask | pdcp_optmask ;
nas_getparams();
if (UE_NAS_USE_TUN) { 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; 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); netlink_init_tun("oaitun_ue", num_if, id);
if (IS_SOFTMODEM_NOS1) 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); 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"); LOG_I(PDCP, "UE pdcp will use tun interface\n");
} else if (ENB_NAS_USE_TUN) { } else if (ENB_NAS_USE_TUN) {
netlink_init_tun("oaitun_enb", 1, 0); 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) { if (pdcp_optmask & ENB_NAS_USE_TUN_W_MBMS_BIT) {
netlink_init_mbms_tun("oaitun_enm", 1); 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 mbms tun interface\n");
} }
LOG_I(PDCP, "ENB pdcp will use tun interface\n"); LOG_I(PDCP, "ENB pdcp will use tun interface\n");
} else if (pdcp_optmask & ENB_NAS_USE_TUN_W_MBMS_BIT) { } else if (pdcp_optmask & ENB_NAS_USE_TUN_W_MBMS_BIT) {
netlink_init_mbms_tun("oaitun_enm", 0); 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"); LOG_I(PDCP, "ENB pdcp will use mbms tun interface\n");
} }
......
...@@ -610,8 +610,6 @@ uint64_t nr_pdcp_module_init(uint64_t _pdcp_optmask, int id) ...@@ -610,8 +610,6 @@ uint64_t nr_pdcp_module_init(uint64_t _pdcp_optmask, int id)
pdcp_optmask = pdcp_optmask | _pdcp_optmask ; pdcp_optmask = pdcp_optmask | _pdcp_optmask ;
nas_getparams();
if (UE_NAS_USE_TUN) { if (UE_NAS_USE_TUN) {
char *ifprefix = get_softmodem_params()->nsa ? "oaitun_nrue" : "oaitun_ue"; 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) 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) ...@@ -619,7 +617,8 @@ uint64_t nr_pdcp_module_init(uint64_t _pdcp_optmask, int id)
: 1; : 1;
netlink_init_tun(ifprefix, num_if, id); netlink_init_tun(ifprefix, num_if, id);
if (IS_SOFTMODEM_NOS1) { 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); set_qfi_pduid(7, 10);
} }
LOG_I(PDCP, "UE pdcp will use tun interface\n"); 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) ...@@ -627,7 +626,7 @@ uint64_t nr_pdcp_module_init(uint64_t _pdcp_optmask, int id)
} else if (ENB_NAS_USE_TUN) { } else if (ENB_NAS_USE_TUN) {
char *ifprefix = get_softmodem_params()->nsa ? "oaitun_gnb" : "oaitun_enb"; char *ifprefix = get_softmodem_params()->nsa ? "oaitun_gnb" : "oaitun_enb";
netlink_init_tun(ifprefix, 1, id); 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"); LOG_I(PDCP, "ENB pdcp will use tun interface\n");
start_pdcp_tun_enb(); start_pdcp_tun_enb();
} }
......
...@@ -765,10 +765,13 @@ rrc_ue_establish_drb( ...@@ -765,10 +765,13 @@ rrc_ue_establish_drb(
ip_addr_offset4 = 1; 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, 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); 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 char ip[20];
UE_NAS_USE_TUN ? 1 : (ip_addr_offset3 + ue_mod_idP + 1), // third_octet snprintf(ip,
ip_addr_offset4 + ue_mod_idP + 1, // fourth_octet sizeof(ip),
"oaitun_oip"); "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 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", LOG_I(OIP,"[UE %d] Config the ue net interface %d to send/receive pkt on DRB %ld to/from the protocol stack\n",
......
...@@ -5255,10 +5255,9 @@ rrc_eNB_process_RRCConnectionReconfigurationComplete( ...@@ -5255,10 +5255,9 @@ rrc_eNB_process_RRCConnectionReconfigurationComplete(
LOG_I(OIP, "[eNB %d] trying to bring up the OAI interface oai%d\n", LOG_I(OIP, "[eNB %d] trying to bring up the OAI interface oai%d\n",
ctxt_pP->module_id, ctxt_pP->module_id,
ctxt_pP->module_id); ctxt_pP->module_id);
oip_ifup = nas_config(ctxt_pP->module_id, // interface index char ip[20];
ctxt_pP->module_id + 1, // third octet snprintf(ip, sizeof(ip), "10.0.%d.%d", ctxt_pP->module_id + 1, ctxt_pP->module_id + 1);
ctxt_pP->module_id + 1, // fourth octet oip_ifup = nas_config(ctxt_pP->module_id, ip, "oaitun_oai");
"oaitun_oai");
if (oip_ifup == 0) { // interface is up --> send a config the DRB if (oip_ifup == 0) { // interface is up --> send a config the DRB
module_id_t ue_module_id; module_id_t ue_module_id;
......
...@@ -29,31 +29,6 @@ ...@@ -29,31 +29,6 @@
#include "nas_config.h" #include "nas_config.h"
#include "common/utils/LOG/log.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 * \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_ ...@@ -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) // 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]; char interfaceName[IFNAMSIZ];
sprintf(ipAddress, "%s.%d.%d", baseNetAddress,thirdOctet,fourthOctet);
snprintf(interfaceName, sizeof(interfaceName), "%s%d", ifpref, interface_id); snprintf(interfaceName, sizeof(interfaceName), "%s%d", ifpref, interface_id);
int sock_fd = socket(AF_INET, SOCK_DGRAM, 0); int sock_fd = socket(AF_INET, SOCK_DGRAM, 0);
if (sock_fd < 0) { if (sock_fd < 0) {
LOG_E(UTIL, "Failed creating socket for interface management: %d, %s\n", errno, strerror(errno)); 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); 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 // set the machine network mask
if (success) if (success)
success = setInterfaceParameter(sock_fd, interfaceName, "255.255.255.0", SIOCSIFNETMASK); 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 ...@@ -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); success = change_interface_state(sock_fd, interfaceName, INTERFACE_UP);
if (success) 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 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); close(sock_fd);
return success; return success;
......
...@@ -19,44 +19,25 @@ ...@@ -19,44 +19,25 @@
* contact@openairinterface.org * 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_ #ifndef NAS_CONFIG_H_
#define NAS_CONFIG_H_ #define NAS_CONFIG_H_
#include <stdbool.h>
#include <netinet/in.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) /*! \fn int nas_config(char*, int, int)
* \brief This function initializes the nasmesh interface using the basic values, * \brief This function initializes the nasmesh interface using the basic values,
* basic address, network mask and broadcast address, as the default configured * basic address, network mask and broadcast address, as the default configured
* ones * ones
* \param[in] interfaceName, the name of the interface, e.g. nasmesh0 or nasmesh1 * \param[in] interface_id number of this interface, prepended after interface
* \param[in] third octet of the ip address e.g. for the 10.1.2.3 address would be 2 * name
* \param[in] fourth octet of the ip address e.g. for the 10.1.2.3 address would be 3 * \param[in] ip IPv4 address of this interface as a string
* \return 0 on success, otherwise 1, if couldn't open a socket and 2 if the ioctl fails * \param[in] ifprefix interface name prefix to which an interface number will
* \note * be appended
* @ingroup _nas * \return true on success, otherwise false
*/
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 * \note
* @ingroup _nas * @ingroup _nas
*/ */
void setBaseNetAddress(char *baseAddr); bool nas_config(int interface_id, const char *ip, const char *ifprefix);
#endif /*NAS_CONFIG_H_*/ #endif /*NAS_CONFIG_H_*/
...@@ -25,8 +25,6 @@ ...@@ -25,8 +25,6 @@
#include "openair2/RRC/NAS/nas_config.h" #include "openair2/RRC/NAS/nas_config.h"
#include "openair2/SDAP/nr_sdap/nr_sdap.h" #include "openair2/SDAP/nr_sdap/nr_sdap.h"
extern char *baseNetAddress;
static uint16_t getShort(uint8_t *input) static uint16_t getShort(uint8_t *input)
{ {
uint16_t tmp16; uint16_t tmp16;
...@@ -105,19 +103,23 @@ void capture_pdu_session_establishment_accept_msg(uint8_t *buffer, uint32_t msg_ ...@@ -105,19 +103,23 @@ void capture_pdu_session_establishment_accept_msg(uint8_t *buffer, uint32_t msg_
psea_msg.pdu_addr_ie.pdu_length = *curPtr++; psea_msg.pdu_addr_ie.pdu_length = *curPtr++;
psea_msg.pdu_addr_ie.pdu_type = *curPtr++; psea_msg.pdu_addr_ie.pdu_type = *curPtr++;
DevAssert(psea_msg.pdu_addr_ie.pdu_type == PDU_SESSION_TYPE_IPV4);
if (psea_msg.pdu_addr_ie.pdu_type == PDU_SESSION_TYPE_IPV4) { if (psea_msg.pdu_addr_ie.pdu_type == PDU_SESSION_TYPE_IPV4) {
psea_msg.pdu_addr_ie.pdu_addr_oct1 = *curPtr++; pdu_address_t *addr = &psea_msg.pdu_addr_ie;
psea_msg.pdu_addr_ie.pdu_addr_oct2 = *curPtr++; addr->pdu_addr_oct1 = *curPtr++;
psea_msg.pdu_addr_ie.pdu_addr_oct3 = *curPtr++; addr->pdu_addr_oct2 = *curPtr++;
psea_msg.pdu_addr_ie.pdu_addr_oct4 = *curPtr++; addr->pdu_addr_oct3 = *curPtr++;
nas_getparams(); addr->pdu_addr_oct4 = *curPtr++;
sprintf(baseNetAddress, "%d.%d", psea_msg.pdu_addr_ie.pdu_addr_oct1, psea_msg.pdu_addr_ie.pdu_addr_oct2); char ip[20];
nas_config(1, psea_msg.pdu_addr_ie.pdu_addr_oct3, psea_msg.pdu_addr_ie.pdu_addr_oct4, "oaitun_ue"); snprintf(ip,
LOG_T(NAS, "PDU SESSION ESTABLISHMENT ACCEPT - Received UE IP: %d.%d.%d.%d\n", sizeof(ip),
psea_msg.pdu_addr_ie.pdu_addr_oct1, "%d.%d.%d.%d",
psea_msg.pdu_addr_ie.pdu_addr_oct2, addr->pdu_addr_oct1,
psea_msg.pdu_addr_ie.pdu_addr_oct3, addr->pdu_addr_oct2,
psea_msg.pdu_addr_ie.pdu_addr_oct4); addr->pdu_addr_oct3,
addr->pdu_addr_oct4);
nas_config(1, ip, "oaitun_ue");
LOG_T(NAS, "PDU SESSION ESTABLISHMENT ACCEPT - Received UE IP: %s\n", ip);
} else { } else {
curPtr += psea_msg.pdu_addr_ie.pdu_length; curPtr += psea_msg.pdu_addr_ie.pdu_length;
} }
......
...@@ -53,7 +53,6 @@ ...@@ -53,7 +53,6 @@
#include "openair3/SECU/nas_stream_eia2.h" #include "openair3/SECU/nas_stream_eia2.h"
#include "openair3/UTILS/conversions.h" #include "openair3/UTILS/conversions.h"
extern char *baseNetAddress;
extern uint16_t NB_UE_INST; extern uint16_t NB_UE_INST;
static nr_ue_nas_t nr_ue_nas = {0}; static nr_ue_nas_t nr_ue_nas = {0};
static nr_nas_msg_snssai_t nas_allowed_nssai[8]; static nr_nas_msg_snssai_t nas_allowed_nssai[8];
...@@ -842,11 +841,11 @@ static void generateRegistrationComplete(nr_ue_nas_t *nas, as_nas_info_t *initia ...@@ -842,11 +841,11 @@ static void generateRegistrationComplete(nr_ue_nas_t *nas, as_nas_info_t *initia
void decodeDownlinkNASTransport(as_nas_info_t *initialNasMsg, uint8_t * pdu_buffer){ void decodeDownlinkNASTransport(as_nas_info_t *initialNasMsg, uint8_t * pdu_buffer){
uint8_t msg_type = *(pdu_buffer + 16); uint8_t msg_type = *(pdu_buffer + 16);
if(msg_type == FGS_PDU_SESSION_ESTABLISHMENT_ACC){ if(msg_type == FGS_PDU_SESSION_ESTABLISHMENT_ACC){
sprintf(baseNetAddress, "%d.%d", *(pdu_buffer + 39),*(pdu_buffer + 40)); uint8_t *ip_p = pdu_buffer + 39;
int third_octet = *(pdu_buffer + 41); char ip[20];
int fourth_octet = *(pdu_buffer + 42); sprintf(ip, "%d.%d.%d.%d", *(ip_p), *(ip_p + 1), *(ip_p + 2), *(ip_p + 3));
LOG_A(NAS, "Received PDU Session Establishment Accept\n"); LOG_A(NAS, "Received PDU Session Establishment Accept\n");
nas_config(1, third_octet, fourth_octet, "oaitun_ue"); nas_config(1, ip, "oaitun_ue");
} else { } else {
LOG_E(NAS, "Received unexpected message in DLinformationTransfer %d\n", msg_type); LOG_E(NAS, "Received unexpected message in DLinformationTransfer %d\n", msg_type);
} }
...@@ -1428,17 +1427,11 @@ void *nas_nrue(void *args_p) ...@@ -1428,17 +1427,11 @@ void *nas_nrue(void *args_p)
while (offset < payload_container_length) { while (offset < payload_container_length) {
if (*(payload_container + offset) == 0x29) { // PDU address IEI if (*(payload_container + offset) == 0x29) { // PDU address IEI
if ((*(payload_container + offset + 1) == 0x05) && (*(payload_container + offset + 2) == 0x01)) { // IPV4 if ((*(payload_container + offset + 1) == 0x05) && (*(payload_container + offset + 2) == 0x01)) { // IPV4
nas_getparams(); uint8_t *ip_p = payload_container + offset + 3;
sprintf(baseNetAddress, "%d.%d", *(payload_container + offset + 3), *(payload_container + offset + 4)); char ip[20];
int third_octet = *(payload_container + offset + 5); snprintf(ip, sizeof(ip), "%d.%d.%d.%d", *(ip_p), *(ip_p + 1), *(ip_p + 2), *(ip_p + 3));
int fourth_octet = *(payload_container + offset + 6); LOG_I(NAS, "Received PDU Session Establishment Accept, UE IP: %s\n", ip);
LOG_I(NAS, nas_config(1, ip, "oaitun_ue");
"Received PDU Session Establishment Accept, UE IP: %d.%d.%d.%d\n",
*(payload_container + offset + 3),
*(payload_container + offset + 4),
*(payload_container + offset + 5),
*(payload_container + offset + 6));
nas_config(1, third_octet, fourth_octet, "oaitun_ue");
break; break;
} }
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment