diff options
Diffstat (limited to 'src/libsystemd-network')
-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 |
4 files changed, 68 insertions, 2 deletions
diff --git a/src/libsystemd-network/dhcp-lease-internal.h b/src/libsystemd-network/dhcp-lease-internal.h index efc7976838..5cbebb4a34 100644 --- a/src/libsystemd-network/dhcp-lease-internal.h +++ b/src/libsystemd-network/dhcp-lease-internal.h @@ -64,6 +64,9 @@ struct sd_dhcp_lease { struct in_addr *pop3_server; size_t pop3_server_size; + struct in_addr *smtp_server; + size_t smtp_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 468bd303dc..1b42712479 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, *pop3_server; - unsigned n_ntp, n_dns, n_sip, n_pop3_server; + struct in_addr *ntp, *dns, *sip, *pop3_server, *smtp_server; + unsigned n_ntp, n_dns, n_sip, n_pop3_server, n_smtp_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 4a6c56ecbf..1b7b6e1068 100644 --- a/src/libsystemd-network/sd-dhcp-lease.c +++ b/src/libsystemd-network/sd-dhcp-lease.c @@ -140,6 +140,17 @@ int sd_dhcp_lease_get_pop3_server(sd_dhcp_lease *lease, const struct in_addr **a return (int) lease->pop3_server_size; } +int sd_dhcp_lease_get_smtp_server(sd_dhcp_lease *lease, const struct in_addr **addr) { + assert_return(lease, -EINVAL); + assert_return(addr, -EINVAL); + + if (lease->smtp_server_size <= 0) + return -ENODATA; + + *addr = lease->smtp_server; + return (int) lease->smtp_server_size; +} + int sd_dhcp_lease_get_domainname(sd_dhcp_lease *lease, const char **domainname) { assert_return(lease, -EINVAL); assert_return(domainname, -EINVAL); @@ -291,6 +302,7 @@ static sd_dhcp_lease *dhcp_lease_free(sd_dhcp_lease *lease) { free(lease->ntp); free(lease->sip); free(lease->pop3_server); + free(lease->smtp_server); free(lease->static_route); free(lease->client_id); free(lease->vendor_specific); @@ -619,6 +631,12 @@ int dhcp_lease_parse_options(uint8_t code, uint8_t len, const void *option, void log_debug_errno(r, "Failed to parse POP3 server, ignoring: %m"); break; + case SD_DHCP_OPTION_SMTP_SERVER: + r = lease_parse_in_addrs(option, len, &lease->smtp_server, &lease->smtp_server_size); + if (r < 0) + log_debug_errno(r, "Failed to parse SMTP 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) @@ -1056,6 +1074,7 @@ int dhcp_lease_load(sd_dhcp_lease **ret, const char *lease_file) { *ntp = NULL, *sip = NULL, *pop3_server = NULL, + *smtp_server = NULL, *mtu = NULL, *routes = NULL, *domains = NULL, @@ -1086,6 +1105,7 @@ int dhcp_lease_load(sd_dhcp_lease **ret, const char *lease_file) { "NTP", &ntp, "SIP", &sip, "POP3_SERVERS", &pop3_server, + "SMTP_SERVERS", &smtp_server, "MTU", &mtu, "DOMAINNAME", &lease->domainname, "HOSTNAME", &lease->hostname, @@ -1206,6 +1226,14 @@ int dhcp_lease_load(sd_dhcp_lease **ret, const char *lease_file) { lease->pop3_server_size = r; } + if (smtp_server) { + r = deserialize_in_addrs(&lease->smtp_server, smtp_server); + if (r < 0) + log_debug_errno(r, "Failed to deserialize SMTP server %s, ignoring: %m", smtp_server); + else + lease->smtp_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 89a487cf01..ee4a7249c2 100644 --- a/src/libsystemd-network/sd-dhcp-server.c +++ b/src/libsystemd-network/sd-dhcp-server.c @@ -141,6 +141,7 @@ static sd_dhcp_server *dhcp_server_free(sd_dhcp_server *server) { free(server->ntp); free(server->sip); free(server->pop3_server); + free(server->smtp_server); hashmap_free(server->leases_by_client_id); @@ -523,6 +524,15 @@ static int server_send_ack(sd_dhcp_server *server, DHCPRequest *req, return r; } + if (server->n_smtp_server > 0) { + r = dhcp_option_append( + &packet->dhcp, req->max_optlen, &offset, 0, + SD_DHCP_OPTION_SMTP_SERVER, + sizeof(struct in_addr) * server->n_smtp_server, server->smtp_server); + if (r < 0) + return r; + } + if (server->timezone) { r = dhcp_option_append( &packet->dhcp, req->max_optlen, &offset, 0, @@ -1216,6 +1226,31 @@ int sd_dhcp_server_set_pop3_server(sd_dhcp_server *server, const struct in_addr return 1; } +int sd_dhcp_server_set_smtp_server(sd_dhcp_server *server, const struct in_addr smtp_server[], unsigned n) { + assert_return(server, -EINVAL); + assert_return(smtp_server || n <= 0, -EINVAL); + + if (server->n_smtp_server == n && + memcmp(server->smtp_server, smtp_server, sizeof(struct in_addr) * n) == 0) + return 0; + + if (n <= 0) { + server->smtp_server = mfree(server->smtp_server); + server->n_smtp_server = 0; + } else { + struct in_addr *c; + + c = newdup(struct in_addr, smtp_server, n); + if (!c) + return -ENOMEM; + + free_and_replace(server->smtp_server, c); + server->n_smtp_server = n; + } + + return 1; +} + int sd_dhcp_server_set_emit_router(sd_dhcp_server *server, int enabled) { assert_return(server, -EINVAL); |