return false;
}
+int link_get_captive_portal(Link *link, const char **ret) {
+ const char *dhcp4_cp = NULL, *dhcp6_cp = NULL, *ndisc_cp = NULL;
+ int r;
+
+ assert(link);
+
+ if (!link->network) {
+ *ret = NULL;
+ return 0;
+ }
+
+ if (link->network->dhcp_use_captive_portal && link->dhcp_lease) {
+ r = sd_dhcp_lease_get_captive_portal(link->dhcp_lease, &dhcp4_cp);
+ if (r < 0 && r != -ENODATA)
+ return r;
+ }
+
+ if (link->network->dhcp6_use_captive_portal && link->dhcp6_lease) {
+ r = sd_dhcp6_lease_get_captive_portal(link->dhcp6_lease, &dhcp6_cp);
+ if (r < 0 && r != -ENODATA)
+ return r;
+ }
+
+ if (link->network->ipv6_accept_ra_use_captive_portal && link->ndisc_captive_portal)
+ ndisc_cp = link->ndisc_captive_portal;
+
+ if (dhcp4_cp) {
+ if (dhcp6_cp && !streq(dhcp4_cp, dhcp6_cp))
+ log_link_debug(link, "DHCPv6 captive portal (%s) does not match DHCPv4 (%s), ignoring DHCPv6 captive portal.",
+ dhcp6_cp, dhcp4_cp);
+
+ if (ndisc_cp && !streq(dhcp4_cp, ndisc_cp))
+ log_link_debug(link, "IPv6RA captive portal (%s) does not match DHCPv4 (%s), ignoring IPv6RA captive portal.",
+ ndisc_cp, dhcp4_cp);
+
+ *ret = dhcp4_cp;
+ return 1;
+ }
+
+ if (dhcp6_cp) {
+ if (ndisc_cp && !streq(dhcp6_cp, ndisc_cp))
+ log_link_debug(link, "IPv6RA captive portal (%s) does not match DHCPv6 (%s), ignoring IPv6RA captive portal.",
+ ndisc_cp, dhcp6_cp);
+
+ *ret = dhcp6_cp;
+ return 1;
+ }
+
+ *ret = ndisc_cp;
+ return !!ndisc_cp;
+}
+
int config_parse_dhcp(
const char* unit,
const char *filename,
#include "ip-protocol-list.h"
#include "netif-util.h"
#include "networkd-address.h"
+#include "networkd-dhcp-common.h"
#include "networkd-json.h"
#include "networkd-link.h"
#include "networkd-manager.h"
}
static int captive_portal_build_json(Link *link, JsonVariant **ret) {
+ const char *captive_portal;
int r;
- const char *captive_portal = NULL;
assert(link);
assert(ret);
- if (!link->network) {
- *ret = NULL;
- return 0;
- }
-
- if (link->network->dhcp_use_captive_portal && link->dhcp_lease) {
- r = sd_dhcp_lease_get_captive_portal(link->dhcp_lease, &captive_portal);
- if (r < 0 && r != -ENODATA)
- return r;
- }
-
- if (link->network->dhcp6_use_captive_portal && link->dhcp6_lease && !captive_portal) {
- r = sd_dhcp6_lease_get_captive_portal(link->dhcp6_lease, &captive_portal);
- if (r < 0 && r != -ENODATA)
- return r;
- }
-
- if (link->network->ipv6_accept_ra_use_captive_portal && !captive_portal)
- captive_portal = link->ndisc_captive_portal;
+ r = link_get_captive_portal(link, &captive_portal);
+ if (r < 0)
+ return r;
if (!captive_portal) {
*ret = NULL;
#include "fileio.h"
#include "fs-util.h"
#include "network-internal.h"
+#include "networkd-dhcp-common.h"
#include "networkd-link.h"
#include "networkd-manager-bus.h"
#include "networkd-manager.h"
int link_save(Link *link) {
const char *admin_state, *oper_state, *carrier_state, *address_state, *ipv4_address_state, *ipv6_address_state,
- *dhcp_captive_portal = NULL, *dhcp6_captive_portal = NULL;
+ *captive_portal;
_cleanup_(unlink_and_freep) char *temp_path = NULL;
_cleanup_fclose_ FILE *f = NULL;
int r;
/************************************************************/
- if (link->dhcp_lease && link->network->dhcp_use_captive_portal) {
- r = sd_dhcp_lease_get_captive_portal(link->dhcp_lease, &dhcp_captive_portal);
- if (r < 0 && r != -ENODATA)
- return r;
- }
-
- if (link->dhcp6_lease && link->network->dhcp6_use_captive_portal) {
- r = sd_dhcp6_lease_get_captive_portal(link->dhcp6_lease, &dhcp6_captive_portal);
- if (r < 0 && r != -ENODATA)
- return r;
- }
-
- if (dhcp6_captive_portal && dhcp_captive_portal && !streq(dhcp_captive_portal, dhcp6_captive_portal))
- log_link_warning(link, "DHCPv6 Captive Portal (%s) does not match DHCPv4 (%s). Ignoring DHCPv6 portal.",
- dhcp6_captive_portal, dhcp_captive_portal);
-
- if (link->network->ipv6_accept_ra_use_captive_portal && link->ndisc_captive_portal) {
- if (dhcp_captive_portal && !streq(dhcp_captive_portal, link->ndisc_captive_portal))
- log_link_warning(link, "IPv6RA captive portal (%s) does not match DHCPv4 (%s). Ignorning IPv6RA portal.",
- link->ndisc_captive_portal, dhcp_captive_portal);
- if (dhcp6_captive_portal && !streq(dhcp6_captive_portal, link->ndisc_captive_portal))
- log_link_warning(link, "IPv6RA captive portal (%s) does not match DHCPv6 (%s). Ignorning IPv6RA portal.",
- link->ndisc_captive_portal, dhcp6_captive_portal);
- }
+ r = link_get_captive_portal(link, &captive_portal);
+ if (r < 0)
+ return r;
- if (dhcp_captive_portal)
- fprintf(f, "CAPTIVE_PORTAL=%s\n", dhcp_captive_portal);
- else if (dhcp6_captive_portal)
- fprintf(f, "CAPTIVE_PORTAL=%s\n", dhcp6_captive_portal);
- else if (link->ndisc_captive_portal)
- fprintf(f, "CAPTIVE_PORTAL=%s\n", link->ndisc_captive_portal);
+ if (captive_portal)
+ fprintf(f, "CAPTIVE_PORTAL=%s\n", captive_portal);
/************************************************************/