Skip to content

Commit

Permalink
raise error on VLAN conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
GIC-de committed Oct 18, 2024
1 parent 33a21f8 commit 65b2174
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 55 deletions.
2 changes: 1 addition & 1 deletion code/bngblaster/src/bbl_access.c
Original file line number Diff line number Diff line change
Expand Up @@ -1757,7 +1757,7 @@ bbl_access_session_id_from_vlan(bbl_access_interface_s *interface,
key.inner_vlan_id = eth->vlan_inner;

search = dict_search(g_ctx->vlan_session_dict, &key);
if(search) {
if(search && *search) {
session = *search;
session_id = session->session_id;
}
Expand Down
2 changes: 1 addition & 1 deletion code/bngblaster/src/bbl_ctrl.c
Original file line number Diff line number Diff line change
Expand Up @@ -438,7 +438,7 @@ bbl_ctrl_socket_thread(void *thread_data)
}
if(key.outer_vlan_id) {
search = dict_search(g_ctx->vlan_session_dict, &key);
if(search) {
if(search && *search) {
session = *search;
session_id = session->session_id;
} else {
Expand Down
64 changes: 17 additions & 47 deletions code/bngblaster/src/bbl_session.c
Original file line number Diff line number Diff line change
Expand Up @@ -782,6 +782,7 @@ bbl_sessions_init()
bbl_access_config_s *access_config;
bbl_access_line_profile_s *access_line_profile;
dict_insert_result result;
void **search;

uint32_t i = 1; /* BNG Blaster internal session identifier */

Expand Down Expand Up @@ -1024,10 +1025,25 @@ bbl_sessions_init()
}

if(access_config->vlan_mode == VLAN_MODE_11) {
/* Add 1:1 sessions to VLAN/session dictionary */
result = dict_insert(g_ctx->vlan_session_dict, &session->vlan_key);
if(result.inserted) {
*result.datum_ptr = session;
} else {
LOG(ERROR, "Failed to create session %u due to VLAN conflict!\n", i);
return false;
}
} else {
search = dict_search(g_ctx->vlan_session_dict, &session->vlan_key);
if(search) {
if(*search) {
LOG(ERROR, "Failed to create session %u due to VLAN conflict!\n", i);
return false;
}
} else {
result = dict_insert(g_ctx->vlan_session_dict, &session->vlan_key);
if(result.inserted) {
*result.datum_ptr = NULL;
}
}
}

Expand Down Expand Up @@ -1079,52 +1095,6 @@ bbl_sessions_init()
return true;
}

uint32_t
bbl_session_id_from_vlan(bbl_interface_s *interface, bbl_ethernet_header_s *eth)
{
uint32_t session_id = 0;
vlan_session_key_t key = {0};
bbl_session_s *session;
void **search;

key.ifindex = interface->ifindex;
key.outer_vlan_id = eth->vlan_outer;
key.inner_vlan_id = eth->vlan_inner;

search = dict_search(g_ctx->vlan_session_dict, &key);
if(search) {
session = *search;
session_id = session->session_id;
}
return session_id;
}

uint32_t
bbl_session_id_from_broadcast(bbl_interface_s *interface, bbl_ethernet_header_s *eth)
{
uint32_t session_id = 0;
bbl_ipv4_s *ipv4;
bbl_udp_s *udp;
bbl_dhcp_s *dhcp;

if(eth->type == ETH_TYPE_IPV4) {
ipv4 = (bbl_ipv4_s*)eth->next;
if(ipv4->protocol == PROTOCOL_IPV4_UDP) {
udp = (bbl_udp_s*)ipv4->next;
if(udp->protocol == UDP_PROTOCOL_DHCP) {
dhcp = (bbl_dhcp_s*)udp->next;
session_id |= ((uint8_t*)(dhcp->header->chaddr))[5];
session_id |= ((uint8_t*)(dhcp->header->chaddr))[4] << 8;
session_id |= ((uint8_t*)(dhcp->header->chaddr))[3] << 16;
}
}
}
if(!session_id) {
return(bbl_session_id_from_vlan(interface, eth));
}
return session_id;
}

const char *
bbl_session_substate_pppoe(bbl_session_s *session)
{
Expand Down
6 changes: 0 additions & 6 deletions code/bngblaster/src/bbl_session.h
Original file line number Diff line number Diff line change
Expand Up @@ -379,12 +379,6 @@ bbl_session_clear(bbl_session_s *session);
bool
bbl_sessions_init();

uint32_t
bbl_session_id_from_vlan(bbl_interface_s *interface, bbl_ethernet_header_s *eth);

uint32_t
bbl_session_id_from_broadcast(bbl_interface_s *interface, bbl_ethernet_header_s *eth);

json_t *
bbl_session_json(bbl_session_s *session);

Expand Down

0 comments on commit 65b2174

Please sign in to comment.