hostapd: update to 2023-03-29
[openwrt/staging/dedeckeh.git] / package / network / services / hostapd / patches / 760-dynamic_own_ip.patch
1 --- a/src/ap/ap_config.h
2 +++ b/src/ap/ap_config.h
3 @@ -310,6 +310,7 @@ struct hostapd_bss_config {
4 unsigned int eap_sim_db_timeout;
5 int eap_server_erp; /* Whether ERP is enabled on internal EAP server */
6 struct hostapd_ip_addr own_ip_addr;
7 + int dynamic_own_ip_addr;
8 char *nas_identifier;
9 struct hostapd_radius_servers *radius;
10 int acct_interim_interval;
11 --- a/src/radius/radius_client.c
12 +++ b/src/radius/radius_client.c
13 @@ -163,6 +163,8 @@ struct radius_client_data {
14 */
15 void *ctx;
16
17 + struct hostapd_ip_addr local_ip;
18 +
19 /**
20 * conf - RADIUS client configuration (list of RADIUS servers to use)
21 */
22 @@ -720,6 +722,30 @@ static void radius_client_list_add(struc
23
24
25 /**
26 + * radius_client_send - Get local address for the RADIUS auth socket
27 + * @radius: RADIUS client context from radius_client_init()
28 + * @addr: pointer to store the address
29 + *
30 + * This function returns the local address for the connection to the RADIUS
31 + * auth server. It also opens the socket if it's not available yet.
32 + */
33 +int radius_client_get_local_addr(struct radius_client_data *radius,
34 + struct hostapd_ip_addr *addr)
35 +{
36 + struct hostapd_radius_servers *conf = radius->conf;
37 +
38 + if (conf->auth_server && radius->auth_sock < 0)
39 + radius_client_init_auth(radius);
40 +
41 + if (radius->auth_sock < 0)
42 + return -1;
43 +
44 + memcpy(addr, &radius->local_ip, sizeof(*addr));
45 +
46 + return 0;
47 +}
48 +
49 +/**
50 * radius_client_send - Send a RADIUS request
51 * @radius: RADIUS client context from radius_client_init()
52 * @msg: RADIUS message to be sent
53 @@ -1238,6 +1264,10 @@ radius_change_server(struct radius_clien
54 wpa_printf(MSG_DEBUG, "RADIUS local address: %s:%u",
55 inet_ntoa(claddr.sin_addr),
56 ntohs(claddr.sin_port));
57 + if (auth) {
58 + radius->local_ip.af = AF_INET;
59 + radius->local_ip.u.v4 = claddr.sin_addr;
60 + }
61 }
62 break;
63 #ifdef CONFIG_IPV6
64 @@ -1249,6 +1279,10 @@ radius_change_server(struct radius_clien
65 inet_ntop(AF_INET6, &claddr6.sin6_addr,
66 abuf, sizeof(abuf)),
67 ntohs(claddr6.sin6_port));
68 + if (auth) {
69 + radius->local_ip.af = AF_INET6;
70 + radius->local_ip.u.v6 = claddr6.sin6_addr;
71 + }
72 }
73 break;
74 }
75 --- a/src/radius/radius_client.h
76 +++ b/src/radius/radius_client.h
77 @@ -249,6 +249,8 @@ int radius_client_register(struct radius
78 void radius_client_set_interim_error_cb(struct radius_client_data *radius,
79 void (*cb)(const u8 *addr, void *ctx),
80 void *ctx);
81 +int radius_client_get_local_addr(struct radius_client_data *radius,
82 + struct hostapd_ip_addr * addr);
83 int radius_client_send(struct radius_client_data *radius,
84 struct radius_msg *msg,
85 RadiusType msg_type, const u8 *addr);
86 --- a/src/ap/ieee802_1x.c
87 +++ b/src/ap/ieee802_1x.c
88 @@ -535,6 +535,10 @@ int add_common_radius_attr(struct hostap
89 struct hostapd_radius_attr *attr;
90 int len;
91
92 + if (hapd->conf->dynamic_own_ip_addr)
93 + radius_client_get_local_addr(hapd->radius,
94 + &hapd->conf->own_ip_addr);
95 +
96 if (!hostapd_config_get_radius_attr(req_attr,
97 RADIUS_ATTR_NAS_IP_ADDRESS) &&
98 hapd->conf->own_ip_addr.af == AF_INET &&
99 --- a/hostapd/config_file.c
100 +++ b/hostapd/config_file.c
101 @@ -2688,6 +2688,8 @@ static int hostapd_config_fill(struct ho
102 } else if (os_strcmp(buf, "iapp_interface") == 0) {
103 wpa_printf(MSG_INFO, "DEPRECATED: iapp_interface not used");
104 #endif /* CONFIG_IAPP */
105 + } else if (os_strcmp(buf, "dynamic_own_ip_addr") == 0) {
106 + bss->dynamic_own_ip_addr = atoi(pos);
107 } else if (os_strcmp(buf, "own_ip_addr") == 0) {
108 if (hostapd_parse_ip_addr(pos, &bss->own_ip_addr)) {
109 wpa_printf(MSG_ERROR,