Skip to content

Commit c4411ea

Browse files
author
Mika Leppänen
committed
Removed extra memory frees from KMP socket and eapol if and fixed KMP comments
1 parent 8088a86 commit c4411ea

File tree

7 files changed

+103
-30
lines changed

7 files changed

+103
-30
lines changed

source/Security/kmp/kmp_addr.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131

3232
#ifdef HAVE_WS
3333

34-
#define TRACE_GROUP "kmpaddr"
34+
#define TRACE_GROUP "kmar"
3535

3636
#define KMP_ADDR_DYN_ALLOC 0x80
3737
#define KMP_ADDR_TYPE_MASK 0x0F

source/Security/kmp/kmp_api.c

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333

3434
#ifdef HAVE_WS
3535

36-
#define TRACE_GROUP "kmpc"
36+
#define TRACE_GROUP "kmap"
3737

3838
struct kmp_api_s {
3939
void *app_data_ptr; /**< Opaque pointer for application data */
@@ -199,14 +199,17 @@ static int8_t kmp_sec_prot_send(sec_prot_t *prot, void *pdu, uint16_t size)
199199
kmp_id -= IEEE_802_1X_INITIAL_KEY;
200200
}
201201

202+
int8_t result = -1;
203+
202204
if (kmp->service->send) {
203-
int8_t result;
204205
result = kmp->service->send(kmp->service, kmp_id, kmp->addr, pdu, size);
205-
return result;
206-
} else {
206+
}
207+
208+
if (result < 0) {
207209
ns_dyn_mem_free(pdu);
208-
return -1;
209210
}
211+
212+
return result;
210213
}
211214

212215
static void kmp_sec_prot_timer_start(sec_prot_t *prot)

source/Security/kmp/kmp_api.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,16 @@
1818
#ifndef KMP_API_H_
1919
#define KMP_API_H_
2020

21+
/*
22+
* KMP API and KMP service module. KMP API offers key management security
23+
* protocols interface towards application.
24+
*
25+
* KMP service provides security protocols access to network, timing
26+
* services and callback services. Application must configure KMP service
27+
* before using KMP API.
28+
*
29+
*/
30+
2131
typedef enum {
2232
IEEE_802_1X_MKA = 1,
2333
IEEE_802_11_4WH = 6,

source/Security/kmp/kmp_eapol_pdu_if.c

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131

3232
#ifdef HAVE_WS
3333

34-
#define TRACE_GROUP "kmpeif"
34+
#define TRACE_GROUP "kmep"
3535

3636
#define EAPOL_PDU_IF_HEADER_SIZE 1
3737

@@ -99,7 +99,6 @@ int8_t kmp_eapol_pdu_if_unregister(kmp_service_t *service)
9999
static int8_t kmp_eapol_pdu_if_send(kmp_service_t *service, kmp_type_e kmp_id, const kmp_addr_t *addr, void *pdu, uint16_t size)
100100
{
101101
if (!service || !addr || !pdu) {
102-
ns_dyn_mem_free(pdu);
103102
return -1;
104103
}
105104

@@ -113,13 +112,11 @@ static int8_t kmp_eapol_pdu_if_send(kmp_service_t *service, kmp_type_e kmp_id, c
113112
}
114113

115114
if (!interface_ptr) {
116-
ns_dyn_mem_free(pdu);
117115
return -1;
118116
}
119117

120118
const uint8_t *eui_64 = kmp_address_eui_64_get(addr);
121119
if (!eui_64) {
122-
ns_dyn_mem_free(pdu);
123120
return -1;
124121
}
125122

source/Security/kmp/kmp_eapol_pdu_if.h

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,45 @@
1818
#ifndef KMP_EAPOL_PDU_IF_H_
1919
#define KMP_EAPOL_PDU_IF_H_
2020

21+
/*
22+
* Supplicant KMP interface to/from EAPOL PDU interface (to MPX).
23+
*/
24+
25+
/**
26+
* kmp_eapol_pdu_if_register register EAPOL PDU interface to KMP service
27+
*
28+
* \param service KMP service to register to
29+
* \param interface_ptr interface
30+
*
31+
* \return < 0 failure
32+
* \return >= 0 success
33+
*
34+
*/
2135
int8_t kmp_eapol_pdu_if_register(kmp_service_t *service, protocol_interface_info_entry_t *interface_ptr);
36+
37+
/**
38+
* kmp_eapol_pdu_if_unregister unregister EAPOL PDU interface from KMP service
39+
*
40+
* \param service KMP service to unregister from
41+
*
42+
* \return < 0 failure
43+
* \return >= 0 success
44+
*
45+
*/
2246
int8_t kmp_eapol_pdu_if_unregister(kmp_service_t *service);
47+
48+
/**
49+
* kmp_eapol_pdu_if_receive receive EAPOL PDU to KMP service
50+
*
51+
* \param interface_ptr interface
52+
* \param eui_64 source EUI-64
53+
* \param pdu EAPOL pdu
54+
* \param size EAPOL pdu size
55+
*
56+
* \return < 0 failure
57+
* \return >= 0 success
58+
*
59+
*/
2360
int8_t kmp_eapol_pdu_if_receive(protocol_interface_info_entry_t *interface_ptr, const uint8_t *eui_64, void *pdu, uint16_t size);
2461

2562
#endif /* KMP_EAPOL_PDU_IF_H_ */

source/Security/kmp/kmp_socket_if.c

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

18-
//#include <stddef.h>
1918
#include "nsconfig.h"
2019
#include <string.h>
2120
#include "ns_types.h"
2221
#include "ns_list.h"
2322
#include "ns_trace.h"
23+
#include "ns_address.h"
2424
#include "nsdynmemLIB.h"
2525
#include "eventOS_event.h"
2626
#include "eventOS_scheduler.h"
@@ -36,13 +36,13 @@
3636

3737
#ifdef HAVE_WS
3838

39-
#define TRACE_GROUP "kmpsif"
39+
#define TRACE_GROUP "kmsi"
4040

4141
#define SOCKET_IF_HEADER_SIZE 27
4242

4343
typedef struct {
4444
kmp_service_t *kmp_service; /**< KMP service */
45-
protocol_interface_info_entry_t *interface_ptr; /**< Interface pointer */
45+
ns_address_t remote_addr; /**< Remote address */
4646
int8_t socket_id; /**< Socket ID */
4747
ns_list_link_t link; /**< Link */
4848
} kmp_socket_if_t;
@@ -52,14 +52,14 @@ static void kmp_socket_if_socket_cb(void *ptr);
5252

5353
static NS_LIST_DEFINE(kmp_socket_if_list, kmp_socket_if_t, link);
5454

55-
int8_t kmp_socket_if_register(kmp_service_t *service, protocol_interface_info_entry_t *interface_ptr)
55+
int8_t kmp_socket_if_register(kmp_service_t *service, uint16_t local_port, const uint8_t *remote_addr, uint16_t remote_port)
5656
{
57-
if (!service || !interface_ptr) {
57+
if (!service || !remote_addr) {
5858
return -1;
5959
}
6060

6161
ns_list_foreach(kmp_socket_if_t, entry, &kmp_socket_if_list) {
62-
if (entry->kmp_service == service || entry->interface_ptr == interface_ptr) {
62+
if (entry->kmp_service == service) {
6363
return -1;
6464
}
6565
}
@@ -70,9 +70,12 @@ int8_t kmp_socket_if_register(kmp_service_t *service, protocol_interface_info_en
7070
}
7171

7272
socket_if->kmp_service = service;
73-
socket_if->interface_ptr = interface_ptr;
74-
socket_if->socket_id = socket_open(IPV6_NH_UDP, 10254, &kmp_socket_if_socket_cb);
7573

74+
socket_if->remote_addr.type = ADDRESS_IPV6;
75+
memcpy(&socket_if->remote_addr.address, remote_addr, 16);
76+
socket_if->remote_addr.identifier = remote_port;
77+
78+
socket_if->socket_id = socket_open(IPV6_NH_UDP, local_port, &kmp_socket_if_socket_cb);
7679
if (socket_if->socket_id < 0) {
7780
ns_dyn_mem_free(socket_if);
7881
return -1;
@@ -108,7 +111,6 @@ int8_t kmp_socket_if_unregister(kmp_service_t *service)
108111
static int8_t kmp_socket_if_send(kmp_service_t *service, kmp_type_e kmp_id, const kmp_addr_t *addr, void *pdu, uint16_t size)
109112
{
110113
if (!service || !pdu || !addr) {
111-
ns_dyn_mem_free(pdu);
112114
return -1;
113115
}
114116

@@ -122,17 +124,9 @@ static int8_t kmp_socket_if_send(kmp_service_t *service, kmp_type_e kmp_id, cons
122124
}
123125

124126
if (!socket_if) {
125-
ns_dyn_mem_free(pdu);
126127
return -1;
127128
}
128129

129-
ns_address_t dest_addr;
130-
if (addr_interface_get_ll_address(socket_if->interface_ptr, &dest_addr.address[0], 1) < 0) {
131-
ns_dyn_mem_free(pdu);
132-
return -1;
133-
}
134-
dest_addr.type = ADDRESS_IPV6;
135-
dest_addr.identifier = 10253;
136130
//Build UPD Relay
137131
uint8_t *ptr = pdu;
138132
memcpy(ptr, kmp_address_ip_get(addr), 16);
@@ -142,8 +136,7 @@ static int8_t kmp_socket_if_send(kmp_service_t *service, kmp_type_e kmp_id, cons
142136
ptr += 8;
143137
*ptr = kmp_id;
144138

145-
socket_sendto(socket_if->socket_id, &dest_addr, pdu, size);
146-
139+
socket_sendto(socket_if->socket_id, &socket_if->remote_addr, pdu, size);
147140
ns_dyn_mem_free(pdu);
148141

149142
return 0;

source/Security/kmp/kmp_socket_if.h

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,40 @@
1818
#ifndef KMP_SOCKET_IF_H_
1919
#define KMP_SOCKET_IF_H_
2020

21-
int8_t kmp_socket_if_register(kmp_service_t *service, protocol_interface_info_entry_t *interface);
21+
/*
22+
* Authenticator KMP socket interface to/from EAPOL authenticator relay. EAPOL
23+
* authenticator relay address and port are provided in register call (remote
24+
* address and remote port parameters)
25+
*
26+
* Authenticator KMP socket must be bound to port that EAPOL authenticator
27+
* uses to send messages to Authenticator KMP. Default port is 10254 (local port
28+
* parameter)
29+
*
30+
*/
31+
32+
/**
33+
* kmp_socket_if_register register socket interface to KMP service
34+
*
35+
* \param service KMP service to register to
36+
* \param local_port local port
37+
* \param remote_addr remote address
38+
* \param remote_port remote port
39+
*
40+
* \return < 0 failure
41+
* \return >= 0 success
42+
*
43+
*/
44+
int8_t kmp_socket_if_register(kmp_service_t *service, uint16_t local_port, const uint8_t *remote_addr, uint16_t remote_port);
45+
46+
/**
47+
* kmp_socket_if_unregister unregister socket interface from KMP service
48+
*
49+
* \param service KMP service to unregister from
50+
*
51+
* \return < 0 failure
52+
* \return >= 0 success
53+
*
54+
*/
2255
int8_t kmp_socket_if_unregister(kmp_service_t *service);
2356

2457
#endif /* KMP_SOCKET_IF_H_ */

0 commit comments

Comments
 (0)