Skip to content

Commit

Permalink
Merge pull request #274 from coova/rfc7710
Browse files Browse the repository at this point in the history
Implement RFC 7710 - Captive Portal URI DHCP option
  • Loading branch information
wlanmac authored Sep 27, 2016
2 parents 41b3103 + 4ae868d commit 41a29c6
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/cmdline.ggo
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,8 @@ option "forcedns1port" - "Force all DNS to a specific port" int default="0" no
option "forcedns2" - "Force all secondary DNS to a specific address" string no
option "forcedns2port" - "Force all secondary DNS to a specific port" int default="0" no

option "rfc7710uri" - "DHCP Captive Portal URI. Defaults to http://uamlisten:uamport/prelogin." string no

option "ipv6" - "Enable IPv6 support" flag off
option "ipv6mode" - "IPv6 mode is either 6and4 (default), 4to6, or 6to4" string no
option "ipv6only" - "Enable IPv6-Only" flag off
Expand Down
9 changes: 9 additions & 0 deletions src/dhcp.c
Original file line number Diff line number Diff line change
Expand Up @@ -3241,6 +3241,15 @@ static int dhcp_accept_opt(struct dhcp_conn_t *conn, uint8_t *o, int pos) {
}
#endif

if (_options.rfc7710uri) {
o[pos++] = DHCP_OPTION_CAPTIVE_PORTAL_URI;
o[pos++] = strlen(_options.rfc7710uri);
memcpy(&o[pos], _options.rfc7710uri, strlen(_options.rfc7710uri));
pos += strlen(_options.rfc7710uri);
if (_options.debug)
syslog(LOG_DEBUG, "DHCP Captive Portal URI %s\n", _options.rfc7710uri);
}

o[pos++] = DHCP_OPTION_END;

return pos;
Expand Down
1 change: 1 addition & 0 deletions src/dhcp.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
#define DHCP_OPTION_CLIENT_IDENTIFIER 61
#define DHCP_OPTION_CLIENT_FQDN 81
#define DHCP_OPTION_82 82
#define DHCP_OPTION_CAPTIVE_PORTAL_URI 160

/* !!highly experimental!! */
#define DHCP_OPTION_CALLED_STATION_ID 197
Expand Down
21 changes: 21 additions & 0 deletions src/main-opt.c
Original file line number Diff line number Diff line change
Expand Up @@ -721,6 +721,27 @@ int main(int argc, char **argv) {
syslog(LOG_DEBUG, "DHCP Listen: %s", inet_ntoa(_options.dhcplisten));
syslog(LOG_DEBUG, "UAM Listen: %s", inet_ntoa(_options.uamlisten));

if (args_info.rfc7710uri_given) {
/*
* When given, but set to an empty string, the feature is disabled.
*/
if (strlen(args_info.rfc7710uri_arg) > 255) {
syslog(LOG_ERR, "Captive portal URI is too long for DHCP option.");
if (!args_info.forgiving_flag)
goto end_processing;
} else {
_options.rfc7710uri = STRDUP(args_info.rfc7710uri_arg);
}
} else {
/*
* When not explicitly set, default to the /prelogin routine.
*/
char uri[128];
snprintf(uri, sizeof(uri), "http://%s:%d/prelogin",
inet_ntoa(_options.uamlisten), _options.uamport);
_options.rfc7710uri = STRDUP(uri);
}

if (!args_info.uamserver_arg) {
syslog(LOG_ERR, "WARNING: No uamserver defiend!");
}
Expand Down
4 changes: 4 additions & 0 deletions src/options.c
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,8 @@ int options_fromfd(int fd, bstring bt) {
if (!option_s_l(bt, &o.routeif)) return 0;
if (!option_s_l(bt, &o.peerkey)) return 0;

if (!option_s_l(bt, &o.rfc7710uri)) return 0;

if (!option_s_l(bt, &o.macsuffix)) return 0;
if (!option_s_l(bt, &o.macpasswd)) return 0;

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

if (!option_s_s(bt, &o.rfc7710uri)) return 0;

if (!option_s_s(bt, &o.macsuffix)) return 0;
if (!option_s_s(bt, &o.macpasswd)) return 0;

Expand Down
2 changes: 2 additions & 0 deletions src/options.h
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,8 @@ struct options_t {
uint32_t ipsrc_num_pass_throughs;
#endif

char* rfc7710uri; /* RFC 7710 URI, nullptr if not used. */

char* uamdomains[MAX_UAM_DOMAINS];
int uamdomain_ttl;

Expand Down

0 comments on commit 41a29c6

Please sign in to comment.