Skip to content

Commit 03469f3

Browse files
author
Mika Leppänen
committed
Modified PAE entities to be bound to interface
- All PAE entities (eapol PDU, relays, PAE supplicant etc.) are now bound to interfaces and can have multiple instances. - Modified relays Now there is eapol-relay which is present for both nodes and border router and connects to MPX. Authenticator relay is now for converting from Wi-Sun EAPOL UDP pdu format to internal format
1 parent 369c8a0 commit 03469f3

25 files changed

+1342
-703
lines changed

source/6LoWPAN/ws/ws_bootstrap.c

Lines changed: 30 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@
6565
#include "6LoWPAN/ws/ws_pae_controller.h"
6666
#include "6LoWPAN/ws/ws_eapol_pdu.h"
6767
#include "6LoWPAN/ws/ws_eapol_auth_relay.h"
68-
#include "6LoWPAN/ws/ws_eapol_supp_relay.h"
68+
#include "ws_eapol_relay.h"
6969

7070
#define TRACE_GROUP "wsbs"
7171

@@ -680,6 +680,9 @@ static int8_t ws_bootstrap_down(protocol_interface_info_entry_t *cur)
680680
nd_proxy_downstream_interface_unregister(cur->id);
681681
ws_nud_table_reset(cur);
682682
dhcp_client_delete(cur->id);
683+
ws_eapol_relay_delete(cur);
684+
ws_eapol_auth_relay_delete(cur);
685+
ws_pae_controller_stop(cur);
683686

684687
return nwk_6lowpan_down(cur);
685688
}
@@ -1374,12 +1377,21 @@ int ws_bootstrap_init(int8_t interface_id, net_6lowpan_mode_e bootstrap_mode)
13741377
}
13751378

13761379
//Init PAE controller and set callback
1377-
ws_pae_controller_init(cur);
1378-
ws_pae_controller_cb_register(&ws_bootstrap_authentication_completed, &ws_bootstrap_key_insert);
1380+
if (ws_pae_controller_init(cur) < 0) {
1381+
ret_val = -4;
1382+
goto init_fail;
1383+
}
1384+
if (ws_pae_controller_cb_register(cur, &ws_bootstrap_authentication_completed, &ws_bootstrap_key_insert) < 0) {
1385+
ret_val = -4;
1386+
goto init_fail;
1387+
}
13791388

13801389
//Init EAPOL PDU handler and register it to MPX
1381-
ws_eapol_pdu_init(cur);
1382-
if (ws_eapol_pdu_mpx_register(mpx_api, MPX_KEY_MANAGEMENT_ENC_USER_ID != 0)) {
1390+
if (ws_eapol_pdu_init(cur) < 0) {
1391+
ret_val = -4;
1392+
goto init_fail;
1393+
}
1394+
if (ws_eapol_pdu_mpx_register(cur, mpx_api, MPX_KEY_MANAGEMENT_ENC_USER_ID != 0)) {
13831395
ret_val = -4;
13841396
// add deallocs
13851397
goto init_fail;
@@ -1425,10 +1437,13 @@ int ws_bootstrap_init(int8_t interface_id, net_6lowpan_mode_e bootstrap_mode)
14251437
//Error handling and free memory
14261438
init_fail:
14271439
lowpan_adaptation_interface_mpx_register(interface_id, NULL, 0);
1440+
ws_eapol_pdu_mpx_register(cur, NULL, 0);
14281441
mac_neighbor_table_delete(mac_neighbor_info(cur));
14291442
etx_storage_list_allocate(cur->id, 0);
14301443
ws_neighbor_class_dealloc(&neigh_info);
14311444
ws_llc_delete(cur);
1445+
ws_eapol_pdu_delete(cur);
1446+
ws_pae_controller_delete(cur);
14321447
return ret_val;
14331448
}
14341449

@@ -1572,9 +1587,8 @@ static void ws_bootstrap_rpl_callback(rpl_event_t event, void *handle)
15721587
tr_debug("Enable DHCPv6 relay");
15731588
dhcp_relay_agent_enable(cur->id, dodag_info.dodag_id);
15741589

1575-
tr_debug("Enable EAPOL relay");
1576-
ws_eapol_supp_relay_init(cur);
1577-
ws_eapol_supp_relay_start(dodag_info.dodag_id);
1590+
tr_debug("Start EAPOL relay");
1591+
ws_eapol_relay_start(cur, dodag_info.dodag_id, 10253);
15781592
}
15791593

15801594
ws_set_fhss_hop(cur);
@@ -1736,9 +1750,9 @@ static void ws_bootstrap_start_discovery(protocol_interface_info_entry_t *cur)
17361750
}
17371751

17381752
// Start authentication
1739-
static void ws_bootstrap_start_authentication(void)
1753+
static void ws_bootstrap_start_authentication(protocol_interface_info_entry_t *cur)
17401754
{
1741-
ws_pae_controller_authenticate();
1755+
ws_pae_controller_authenticate(cur);
17421756
}
17431757

17441758

@@ -2046,9 +2060,10 @@ static void ws_bootstrap_event_handler(arm_event_s *event)
20462060
ws_bootstrap_set_test_key(cur);
20472061
ws_bootstrap_event_operation_start(cur);
20482062

2049-
ws_eapol_auth_relay_init(cur);
2050-
ws_eapol_auth_relay_start();
2051-
ws_pae_controller_authenticator_start();
2063+
ws_eapol_relay_start(cur, 0, 10255);
2064+
ws_eapol_auth_relay_start(cur);
2065+
2066+
ws_pae_controller_authenticator_start(cur);
20522067
break;
20532068
}
20542069
// Configure LLC for network discovery
@@ -2070,7 +2085,7 @@ static void ws_bootstrap_event_handler(arm_event_s *event)
20702085
cur->ws_info->trickle_pas_running = false;
20712086
cur->ws_info->trickle_pcs_running = false;
20722087

2073-
ws_bootstrap_start_authentication();
2088+
ws_bootstrap_start_authentication(cur);
20742089
break;
20752090

20762091
case WS_CONFIGURATION_START:
@@ -2155,7 +2170,7 @@ void ws_bootstrap_network_scan_process(protocol_interface_info_entry_t *cur)
21552170
ws_bootstrap_network_information_learn(cur);
21562171
ws_bootstrap_fhss_activate(cur);
21572172

2158-
ws_pae_controller_set_target(cur->ws_info->parent_info.addr); // temporary!!! store since auth
2173+
ws_pae_controller_set_target(cur, cur->ws_info->parent_info.addr); // temporary!!! store since auth
21592174
ws_bootstrap_event_authentication_start(cur);
21602175
return;
21612176
}

source/6LoWPAN/ws/ws_eapol_auth_relay.c

Lines changed: 116 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
* limitations under the License.
1616
*/
1717

18-
1918
#include "nsconfig.h"
2019
#include <string.h>
2120
#include "ns_types.h"
@@ -32,70 +31,120 @@
3231
#include "6LoWPAN/MAC/mpx_api.h"
3332
#include "6LoWPAN/ws/ws_config.h"
3433
#include "6LoWPAN/ws/ws_eapol_pdu.h"
35-
#include "6LoWPAN/ws/ws_eapol_relay.h"
34+
#include "6LoWPAN/ws/ws_eapol_relay_lib.h"
3635
#include "6LoWPAN/ws/ws_eapol_auth_relay.h"
3736
#include "common_functions.h"
3837

3938
#ifdef HAVE_WS
4039
#ifdef HAVE_PAE_AUTH
4140

42-
#define TRACE_GROUP "wspsu"
41+
#define TRACE_GROUP "earl"
42+
43+
typedef struct {
44+
protocol_interface_info_entry_t *interface_ptr; /**< Interface pointer */
45+
int8_t socket_id; /**< Socket ID for relay */
46+
ns_list_link_t link; /**< Link */
47+
} eapol_auth_relay_t;
4348

44-
static int8_t ws_eapol_auth_relay_eapol_pdu_address_check(const uint8_t *eui_64);
45-
static int8_t ws_eapol_auth_relay_eapol_pdu_receive(const uint8_t *eui_64, const void *pdu, uint16_t size);
46-
static int8_t ws_eapol_auth_relay_socket_pdu_receive(const ns_address_t *src_addr, void *data, uint16_t len);
47-
static int8_t ws_eapol_auth_relay_send_to_kmp(const uint8_t *eui_64, const uint8_t *ip_addr, uint16_t port, const void *data, uint16_t data_len);
49+
static eapol_auth_relay_t *ws_eapol_auth_relay_get(protocol_interface_info_entry_t *interface_ptr);
50+
static void ws_eapol_auth_relay_socket_cb(void *cb);
51+
static int8_t ws_eapol_auth_relay_send_to_kmp(const eapol_auth_relay_t *eapol_auth_relay, const uint8_t *eui_64, const uint8_t *ip_addr, uint16_t port, const void *data, uint16_t data_len);
4852

49-
static bool relay_initiated = false;
53+
static NS_LIST_DEFINE(eapol_auth_relay_list, eapol_auth_relay_t, link);
5054

51-
int8_t ws_eapol_auth_relay_init(protocol_interface_info_entry_t *interface_ptr)
55+
int8_t ws_eapol_auth_relay_start(protocol_interface_info_entry_t *interface_ptr)
5256
{
53-
if (relay_initiated) {
54-
return 0;
57+
if (!interface_ptr) {
58+
return -1;
5559
}
56-
relay_initiated = true;
5760

58-
ws_eapol_relay_init(interface_ptr);
59-
ws_eapol_relay_cb_register(ws_eapol_auth_relay_socket_pdu_receive);
61+
if (ws_eapol_auth_relay_get(interface_ptr)) {
62+
return -1;
63+
}
6064

61-
eapol_pdu_recv_cb_data_t cb_data;
62-
cb_data.priority = EAPOL_PDU_RECV_LOW_PRIORITY;
63-
cb_data.addr_check = ws_eapol_auth_relay_eapol_pdu_address_check;
64-
cb_data.receive = ws_eapol_auth_relay_eapol_pdu_receive;
65+
eapol_auth_relay_t *eapol_auth_relay = ns_dyn_mem_alloc(sizeof(eapol_auth_relay_t));
66+
if (!eapol_auth_relay) {
67+
return -1;
68+
}
6569

66-
if (ws_eapol_pdu_cb_register(&cb_data) < 0) {
70+
eapol_auth_relay->interface_ptr = interface_ptr;
71+
eapol_auth_relay->socket_id = socket_open(IPV6_NH_UDP, 10253, &ws_eapol_auth_relay_socket_cb);
72+
if (eapol_auth_relay->socket_id < 0) {
73+
ns_dyn_mem_free(eapol_auth_relay);
6774
return -1;
6875
}
6976

70-
return 0;
71-
}
77+
ns_list_add_to_end(&eapol_auth_relay_list, eapol_auth_relay);
7278

73-
int8_t ws_eapol_auth_relay_start(void)
74-
{
7579
return 0;
7680
}
7781

78-
static int8_t ws_eapol_auth_relay_eapol_pdu_address_check(const uint8_t *eui_64)
82+
int8_t ws_eapol_auth_relay_delete(protocol_interface_info_entry_t *interface_ptr)
7983
{
80-
(void) eui_64;
84+
if (!interface_ptr) {
85+
return -1;
86+
}
87+
88+
eapol_auth_relay_t *eapol_auth_relay = ws_eapol_auth_relay_get(interface_ptr);
89+
if (!eapol_auth_relay) {
90+
return -1;
91+
}
92+
93+
socket_close(eapol_auth_relay->socket_id);
94+
95+
ns_list_remove(&eapol_auth_relay_list, eapol_auth_relay);
96+
ns_dyn_mem_free(eapol_auth_relay);
8197

82-
// Low priority, always route all here if asked
8398
return 0;
8499
}
85100

86-
static int8_t ws_eapol_auth_relay_eapol_pdu_receive(const uint8_t *eui_64, const void *pdu, uint16_t size)
101+
static eapol_auth_relay_t *ws_eapol_auth_relay_get(protocol_interface_info_entry_t *interface_ptr)
87102
{
88-
ws_eapol_auth_relay_send_to_kmp(eui_64, ADDR_UNSPECIFIED, 0, pdu, size);
89-
return 0;
103+
ns_list_foreach(eapol_auth_relay_t, entry, &eapol_auth_relay_list) {
104+
if (entry->interface_ptr == interface_ptr) {
105+
return entry;
106+
}
107+
}
108+
109+
return NULL;
90110
}
91111

92-
static int8_t ws_eapol_auth_relay_socket_pdu_receive(const ns_address_t *src_addr, void *data, uint16_t len)
112+
static void ws_eapol_auth_relay_socket_cb(void *cb)
93113
{
94-
int8_t res = 0;
114+
socket_callback_t *cb_data = cb;
115+
116+
if (cb_data->event_type != SOCKET_DATA) {
117+
return;
118+
}
119+
120+
eapol_auth_relay_t *eapol_auth_relay = NULL;
121+
122+
ns_list_foreach(eapol_auth_relay_t, entry, &eapol_auth_relay_list) {
123+
if (entry->socket_id == cb_data->socket_id) {
124+
eapol_auth_relay = entry;
125+
break;
126+
}
127+
}
128+
129+
if (!eapol_auth_relay) {
130+
return;
131+
}
132+
133+
uint8_t *socket_pdu = ns_dyn_mem_temporary_alloc(cb_data->d_len);
134+
if (!socket_pdu) {
135+
return;
136+
}
137+
138+
ns_address_t src_addr;
139+
140+
if (socket_recvfrom(cb_data->socket_id, socket_pdu, cb_data->d_len, 0, &src_addr) != cb_data->d_len) {
141+
ns_dyn_mem_free(socket_pdu);
142+
return;
143+
}
95144

96-
// KMP message from source port 10254
97-
if (src_addr->identifier == 10254) {
98-
uint8_t *ptr = data;
145+
// Message from source port 10254 (KMP service) -> to IP relay on node or on authenticator
146+
if (src_addr.identifier == 10254) {
147+
uint8_t *ptr = socket_pdu;
99148
uint8_t *relay_ip_addr, *eui_64;
100149
uint16_t relay_port;
101150
relay_ip_addr = ptr;
@@ -104,65 +153,48 @@ static int8_t ws_eapol_auth_relay_socket_pdu_receive(const ns_address_t *src_add
104153
ptr += 2;
105154
eui_64 = ptr;
106155
ptr += 8;
107-
uint16_t data_len = len - 26;
108-
// KMP protocol to relay -> packet with IP relay address -> to IP relay of node
109-
if (memcmp(relay_ip_addr, ADDR_UNSPECIFIED, 16) != 0) {
110-
res = ws_eapol_relay_send_to_relay(eui_64, relay_ip_addr, relay_port,
111-
ptr, data_len);
112-
ns_dyn_mem_free(data);
113-
114-
// KMP protocol to relay -> no IP relay address -> to MPX
115-
} else {
116-
res = ws_eapol_pdu_send_to_mpx(eui_64, ptr, data_len, data);
117-
}
118-
119-
120-
// Other source port (either 10253 or node relay source port)
156+
uint16_t data_len = cb_data->d_len - 26;
157+
ws_eapol_relay_lib_send_to_relay(eapol_auth_relay->socket_id, eui_64, relay_ip_addr, relay_port,
158+
ptr, data_len);
159+
ns_dyn_mem_free(socket_pdu);
160+
// Other source port (either 10253 or node relay source port) -> to KMP service
121161
} else {
122-
uint8_t *ptr = data;
123-
res = ws_eapol_auth_relay_send_to_kmp(ptr, src_addr->address, src_addr->identifier,
124-
ptr + 8, len -8);
125-
ns_dyn_mem_free(data);
126-
}
127-
128-
return res;
162+
uint8_t *ptr = socket_pdu;
163+
ws_eapol_auth_relay_send_to_kmp(eapol_auth_relay, ptr, src_addr.address, src_addr.identifier,
164+
ptr + 8, cb_data->d_len - 8);
165+
ns_dyn_mem_free(socket_pdu);
166+
}
129167
}
130168

131-
static int8_t ws_eapol_auth_relay_send_to_kmp(const uint8_t *eui_64, const uint8_t *ip_addr, uint16_t port, const void *data, uint16_t data_len)
169+
static int8_t ws_eapol_auth_relay_send_to_kmp(const eapol_auth_relay_t *eapol_auth_relay, const uint8_t *eui_64, const uint8_t *ip_addr, uint16_t port, const void *data, uint16_t data_len)
132170
{
133171
ns_address_t dest_addr;
134172

135-
if (ws_eapol_relay_kmp_ll_address_get(&dest_addr) < 0) {
173+
if (ws_eapol_relay_lib_ll_address_get(eapol_auth_relay->interface_ptr, &dest_addr) < 0) {
136174
return -1;
137175
}
138176

139-
int8_t socket_id = ws_eapol_relay_socket_id_get();
140-
if (socket_id >= 0) {
141-
uint8_t temp_array[26];
142-
ns_iovec_t msg_iov[2];
143-
ns_msghdr_t msghdr;
144-
//Set messages name buffer
145-
msghdr.msg_name = &dest_addr;
146-
msghdr.msg_namelen = sizeof(dest_addr);
147-
msghdr.msg_iov = &msg_iov[0];
148-
msghdr.msg_iovlen = 2;
149-
msghdr.msg_control = NULL;
150-
msghdr.msg_controllen = 0;
151-
uint8_t *ptr = temp_array;
152-
memcpy(ptr, ip_addr, 16);
153-
ptr += 16;
154-
ptr = common_write_16_bit(port, ptr);
155-
memcpy(ptr, eui_64, 8);
156-
msg_iov[0].iov_base = temp_array;
157-
msg_iov[0].iov_len = 26;
158-
msg_iov[1].iov_base = (void*)data;
159-
msg_iov[1].iov_len = data_len;
160-
socket_sendmsg(socket_id, &msghdr, NS_MSG_LEGACY0);
161-
return 0;
162-
163-
}
164-
165-
return -1;
177+
uint8_t temp_array[26];
178+
ns_iovec_t msg_iov[2];
179+
ns_msghdr_t msghdr;
180+
//Set messages name buffer
181+
msghdr.msg_name = &dest_addr;
182+
msghdr.msg_namelen = sizeof(dest_addr);
183+
msghdr.msg_iov = &msg_iov[0];
184+
msghdr.msg_iovlen = 2;
185+
msghdr.msg_control = NULL;
186+
msghdr.msg_controllen = 0;
187+
uint8_t *ptr = temp_array;
188+
memcpy(ptr, ip_addr, 16);
189+
ptr += 16;
190+
ptr = common_write_16_bit(port, ptr);
191+
memcpy(ptr, eui_64, 8);
192+
msg_iov[0].iov_base = temp_array;
193+
msg_iov[0].iov_len = 26;
194+
msg_iov[1].iov_base = (void*)data;
195+
msg_iov[1].iov_len = data_len;
196+
socket_sendmsg(eapol_auth_relay->socket_id, &msghdr, NS_MSG_LEGACY0);
197+
return 0;
166198
}
167199

168200
#endif /* HAVE_PAE_AUTH */

source/6LoWPAN/ws/ws_eapol_auth_relay.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,13 @@
2020

2121
#ifdef HAVE_PAE_AUTH
2222

23-
int8_t ws_eapol_auth_relay_init(protocol_interface_info_entry_t *interface_ptr);
24-
int8_t ws_eapol_auth_relay_start(void);
23+
int8_t ws_eapol_auth_relay_start(protocol_interface_info_entry_t *interface_ptr);
24+
int8_t ws_eapol_auth_relay_delete(protocol_interface_info_entry_t *interface_ptr);
2525

2626
#else
2727

28-
#define ws_eapol_auth_relay_init(interface_ptr)
29-
#define ws_eapol_auth_relay_start()
28+
#define ws_eapol_auth_relay_start(interface_ptr)
29+
#define ws_eapol_auth_relay_delete(interface_ptr)
3030

3131
#endif
3232

0 commit comments

Comments
 (0)