Skip to content

Commit 41a29c6

Browse files
authored
Merge pull request #274 from coova/rfc7710
Implement RFC 7710 - Captive Portal URI DHCP option
2 parents 41b3103 + 4ae868d commit 41a29c6

File tree

6 files changed

+39
-0
lines changed

6 files changed

+39
-0
lines changed

src/cmdline.ggo

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,8 @@ option "forcedns1port" - "Force all DNS to a specific port" int default="0" no
290290
option "forcedns2" - "Force all secondary DNS to a specific address" string no
291291
option "forcedns2port" - "Force all secondary DNS to a specific port" int default="0" no
292292

293+
option "rfc7710uri" - "DHCP Captive Portal URI. Defaults to http://uamlisten:uamport/prelogin." string no
294+
293295
option "ipv6" - "Enable IPv6 support" flag off
294296
option "ipv6mode" - "IPv6 mode is either 6and4 (default), 4to6, or 6to4" string no
295297
option "ipv6only" - "Enable IPv6-Only" flag off

src/dhcp.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3241,6 +3241,15 @@ static int dhcp_accept_opt(struct dhcp_conn_t *conn, uint8_t *o, int pos) {
32413241
}
32423242
#endif
32433243

3244+
if (_options.rfc7710uri) {
3245+
o[pos++] = DHCP_OPTION_CAPTIVE_PORTAL_URI;
3246+
o[pos++] = strlen(_options.rfc7710uri);
3247+
memcpy(&o[pos], _options.rfc7710uri, strlen(_options.rfc7710uri));
3248+
pos += strlen(_options.rfc7710uri);
3249+
if (_options.debug)
3250+
syslog(LOG_DEBUG, "DHCP Captive Portal URI %s\n", _options.rfc7710uri);
3251+
}
3252+
32443253
o[pos++] = DHCP_OPTION_END;
32453254

32463255
return pos;

src/dhcp.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
#define DHCP_OPTION_CLIENT_IDENTIFIER 61
4848
#define DHCP_OPTION_CLIENT_FQDN 81
4949
#define DHCP_OPTION_82 82
50+
#define DHCP_OPTION_CAPTIVE_PORTAL_URI 160
5051

5152
/* !!highly experimental!! */
5253
#define DHCP_OPTION_CALLED_STATION_ID 197

src/main-opt.c

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -721,6 +721,27 @@ int main(int argc, char **argv) {
721721
syslog(LOG_DEBUG, "DHCP Listen: %s", inet_ntoa(_options.dhcplisten));
722722
syslog(LOG_DEBUG, "UAM Listen: %s", inet_ntoa(_options.uamlisten));
723723

724+
if (args_info.rfc7710uri_given) {
725+
/*
726+
* When given, but set to an empty string, the feature is disabled.
727+
*/
728+
if (strlen(args_info.rfc7710uri_arg) > 255) {
729+
syslog(LOG_ERR, "Captive portal URI is too long for DHCP option.");
730+
if (!args_info.forgiving_flag)
731+
goto end_processing;
732+
} else {
733+
_options.rfc7710uri = STRDUP(args_info.rfc7710uri_arg);
734+
}
735+
} else {
736+
/*
737+
* When not explicitly set, default to the /prelogin routine.
738+
*/
739+
char uri[128];
740+
snprintf(uri, sizeof(uri), "http://%s:%d/prelogin",
741+
inet_ntoa(_options.uamlisten), _options.uamport);
742+
_options.rfc7710uri = STRDUP(uri);
743+
}
744+
724745
if (!args_info.uamserver_arg) {
725746
syslog(LOG_ERR, "WARNING: No uamserver defiend!");
726747
}

src/options.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,8 @@ int options_fromfd(int fd, bstring bt) {
306306
if (!option_s_l(bt, &o.routeif)) return 0;
307307
if (!option_s_l(bt, &o.peerkey)) return 0;
308308

309+
if (!option_s_l(bt, &o.rfc7710uri)) return 0;
310+
309311
if (!option_s_l(bt, &o.macsuffix)) return 0;
310312
if (!option_s_l(bt, &o.macpasswd)) return 0;
311313

@@ -507,6 +509,8 @@ int options_save(char *file, bstring bt) {
507509
if (!option_s_s(bt, &o.routeif)) return 0;
508510
if (!option_s_s(bt, &o.peerkey)) return 0;
509511

512+
if (!option_s_s(bt, &o.rfc7710uri)) return 0;
513+
510514
if (!option_s_s(bt, &o.macsuffix)) return 0;
511515
if (!option_s_s(bt, &o.macpasswd)) return 0;
512516

src/options.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -322,6 +322,8 @@ struct options_t {
322322
uint32_t ipsrc_num_pass_throughs;
323323
#endif
324324

325+
char* rfc7710uri; /* RFC 7710 URI, nullptr if not used. */
326+
325327
char* uamdomains[MAX_UAM_DOMAINS];
326328
int uamdomain_ttl;
327329

0 commit comments

Comments
 (0)