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