diff options
-rw-r--r-- | src/libsystemd-network/dhcp-lease-internal.h | 3 | ||||
-rw-r--r-- | src/libsystemd-network/dhcp-server-internal.h | 4 | ||||
-rw-r--r-- | src/libsystemd-network/sd-dhcp-lease.c | 28 | ||||
-rw-r--r-- | src/libsystemd-network/sd-dhcp-server.c | 35 | ||||
-rw-r--r-- | src/systemd/sd-dhcp-client.h | 1 | ||||
-rw-r--r-- | src/systemd/sd-dhcp-lease.h | 1 | ||||
-rw-r--r-- | src/systemd/sd-dhcp-server.h | 1 |
7 files changed, 71 insertions, 2 deletions
diff --git a/src/libsystemd-network/dhcp-lease-internal.h b/src/libsystemd-network/dhcp-lease-internal.h index a2d0f8bd5e..efc7976838 100644 --- a/src/libsystemd-network/dhcp-lease-internal.h +++ b/src/libsystemd-network/dhcp-lease-internal.h @@ -61,6 +61,9 @@ struct sd_dhcp_lease { struct in_addr *sip; size_t sip_size; + struct in_addr *pop3_server; + size_t pop3_server_size; + struct sd_dhcp_route *static_route; size_t static_route_size, static_route_allocated; diff --git a/src/libsystemd-network/dhcp-server-internal.h b/src/libsystemd-network/dhcp-server-internal.h index 41901894f5..468bd303dc 100644 --- a/src/libsystemd-network/dhcp-server-internal.h +++ b/src/libsystemd-network/dhcp-server-internal.h @@ -55,8 +55,8 @@ struct sd_dhcp_server { char *timezone; - struct in_addr *ntp, *dns, *sip; - unsigned n_ntp, n_dns, n_sip; + struct in_addr *ntp, *dns, *sip, *pop3_server; + unsigned n_ntp, n_dns, n_sip, n_pop3_server; OrderedHashmap *extra_options; OrderedHashmap *vendor_options; diff --git a/src/libsystemd-network/sd-dhcp-lease.c b/src/libsystemd-network/sd-dhcp-lease.c index d072f1c57a..4a6c56ecbf 100644 --- a/src/libsystemd-network/sd-dhcp-lease.c +++ b/src/libsystemd-network/sd-dhcp-lease.c @@ -129,6 +129,17 @@ int sd_dhcp_lease_get_sip(sd_dhcp_lease *lease, const struct in_addr **addr) { return (int) lease->sip_size; } +int sd_dhcp_lease_get_pop3_server(sd_dhcp_lease *lease, const struct in_addr **addr) { + assert_return(lease, -EINVAL); + assert_return(addr, -EINVAL); + + if (lease->pop3_server_size <= 0) + return -ENODATA; + + *addr = lease->pop3_server; + return (int) lease->pop3_server_size; +} + int sd_dhcp_lease_get_domainname(sd_dhcp_lease *lease, const char **domainname) { assert_return(lease, -EINVAL); assert_return(domainname, -EINVAL); @@ -279,6 +290,7 @@ static sd_dhcp_lease *dhcp_lease_free(sd_dhcp_lease *lease) { free(lease->dns); free(lease->ntp); free(lease->sip); + free(lease->pop3_server); free(lease->static_route); free(lease->client_id); free(lease->vendor_specific); @@ -601,6 +613,12 @@ int dhcp_lease_parse_options(uint8_t code, uint8_t len, const void *option, void log_debug_errno(r, "Failed to parse SIP server, ignoring: %m"); break; + case SD_DHCP_OPTION_POP3_SERVER: + r = lease_parse_in_addrs(option, len, &lease->pop3_server, &lease->pop3_server_size); + if (r < 0) + log_debug_errno(r, "Failed to parse POP3 server, ignoring: %m"); + break; + case SD_DHCP_OPTION_STATIC_ROUTE: r = lease_parse_routes(option, len, &lease->static_route, &lease->static_route_size, &lease->static_route_allocated); if (r < 0) @@ -1037,6 +1055,7 @@ int dhcp_lease_load(sd_dhcp_lease **ret, const char *lease_file) { *dns = NULL, *ntp = NULL, *sip = NULL, + *pop3_server = NULL, *mtu = NULL, *routes = NULL, *domains = NULL, @@ -1066,6 +1085,7 @@ int dhcp_lease_load(sd_dhcp_lease **ret, const char *lease_file) { "DNS", &dns, "NTP", &ntp, "SIP", &sip, + "POP3_SERVERS", &pop3_server, "MTU", &mtu, "DOMAINNAME", &lease->domainname, "HOSTNAME", &lease->hostname, @@ -1178,6 +1198,14 @@ int dhcp_lease_load(sd_dhcp_lease **ret, const char *lease_file) { lease->sip_size = r; } + if (pop3_server) { + r = deserialize_in_addrs(&lease->pop3_server, pop3_server); + if (r < 0) + log_debug_errno(r, "Failed to deserialize POP3 server %s, ignoring: %m", pop3_server); + else + lease->pop3_server_size = r; + } + if (mtu) { r = safe_atou16(mtu, &lease->mtu); if (r < 0) diff --git a/src/libsystemd-network/sd-dhcp-server.c b/src/libsystemd-network/sd-dhcp-server.c index a0b779bc09..89a487cf01 100644 --- a/src/libsystemd-network/sd-dhcp-server.c +++ b/src/libsystemd-network/sd-dhcp-server.c @@ -140,6 +140,7 @@ static sd_dhcp_server *dhcp_server_free(sd_dhcp_server *server) { free(server->dns); free(server->ntp); free(server->sip); + free(server->pop3_server); hashmap_free(server->leases_by_client_id); @@ -513,6 +514,15 @@ static int server_send_ack(sd_dhcp_server *server, DHCPRequest *req, return r; } + if (server->n_pop3_server > 0) { + r = dhcp_option_append( + &packet->dhcp, req->max_optlen, &offset, 0, + SD_DHCP_OPTION_POP3_SERVER, + sizeof(struct in_addr) * server->n_pop3_server, server->pop3_server); + if (r < 0) + return r; + } + if (server->timezone) { r = dhcp_option_append( &packet->dhcp, req->max_optlen, &offset, 0, @@ -1181,6 +1191,31 @@ int sd_dhcp_server_set_sip(sd_dhcp_server *server, const struct in_addr sip[], u return 1; } +int sd_dhcp_server_set_pop3_server(sd_dhcp_server *server, const struct in_addr pop3_server[], unsigned n) { + assert_return(server, -EINVAL); + assert_return(pop3_server || n <= 0, -EINVAL); + + if (server->n_pop3_server == n && + memcmp(server->pop3_server, pop3_server, sizeof(struct in_addr) * n) == 0) + return 0; + + if (n <= 0) { + server->pop3_server = mfree(server->pop3_server); + server->n_pop3_server = 0; + } else { + struct in_addr *c; + + c = newdup(struct in_addr, pop3_server, n); + if (!c) + return -ENOMEM; + + free_and_replace(server->pop3_server, c); + server->n_pop3_server = n; + } + + return 1; +} + int sd_dhcp_server_set_emit_router(sd_dhcp_server *server, int enabled) { assert_return(server, -EINVAL); diff --git a/src/systemd/sd-dhcp-client.h b/src/systemd/sd-dhcp-client.h index 9dd562fa43..b8ffe78468 100644 --- a/src/systemd/sd-dhcp-client.h +++ b/src/systemd/sd-dhcp-client.h @@ -83,6 +83,7 @@ enum { SD_DHCP_OPTION_REBINDING_T2_TIME = 59, SD_DHCP_OPTION_VENDOR_CLASS_IDENTIFIER = 60, SD_DHCP_OPTION_CLIENT_IDENTIFIER = 61, + SD_DHCP_OPTION_POP3_SERVER = 70, SD_DHCP_OPTION_USER_CLASS = 77, SD_DHCP_OPTION_FQDN = 81, SD_DHCP_OPTION_NEW_POSIX_TIMEZONE = 100, diff --git a/src/systemd/sd-dhcp-lease.h b/src/systemd/sd-dhcp-lease.h index b80d607fea..e216c768d4 100644 --- a/src/systemd/sd-dhcp-lease.h +++ b/src/systemd/sd-dhcp-lease.h @@ -45,6 +45,7 @@ int sd_dhcp_lease_get_server_identifier(sd_dhcp_lease *lease, struct in_addr *ad int sd_dhcp_lease_get_dns(sd_dhcp_lease *lease, const struct in_addr **addr); int sd_dhcp_lease_get_ntp(sd_dhcp_lease *lease, const struct in_addr **addr); int sd_dhcp_lease_get_sip(sd_dhcp_lease *lease, const struct in_addr **addr); +int sd_dhcp_lease_get_pop3_server(sd_dhcp_lease *lease, const struct in_addr **addr); int sd_dhcp_lease_get_mtu(sd_dhcp_lease *lease, uint16_t *mtu); int sd_dhcp_lease_get_domainname(sd_dhcp_lease *lease, const char **domainname); int sd_dhcp_lease_get_search_domains(sd_dhcp_lease *lease, char ***domains); diff --git a/src/systemd/sd-dhcp-server.h b/src/systemd/sd-dhcp-server.h index 55272b5164..98db7aded5 100644 --- a/src/systemd/sd-dhcp-server.h +++ b/src/systemd/sd-dhcp-server.h @@ -50,6 +50,7 @@ int sd_dhcp_server_set_timezone(sd_dhcp_server *server, const char *timezone); int sd_dhcp_server_set_dns(sd_dhcp_server *server, const struct in_addr dns[], unsigned n); int sd_dhcp_server_set_ntp(sd_dhcp_server *server, const struct in_addr ntp[], unsigned n); int sd_dhcp_server_set_sip(sd_dhcp_server *server, const struct in_addr sip[], unsigned n); +int sd_dhcp_server_set_pop3_server(sd_dhcp_server *server, const struct in_addr pop3_server[], unsigned n); int sd_dhcp_server_set_emit_router(sd_dhcp_server *server, int enabled); int sd_dhcp_server_add_option(sd_dhcp_server *server, sd_dhcp_option *v); |