diff options
author | Susant Sahani <ssahani@vmware.com> | 2020-04-22 14:48:11 +0200 |
---|---|---|
committer | Susant Sahani <ssahani@vmware.com> | 2020-04-22 14:48:11 +0200 |
commit | 50018bfa84f5f0a0271e7656264d303e034dcf4d (patch) | |
tree | d3916f8b9cb29ec99fcd956c17983e185847a595 | |
parent | Merge pull request #15508 from keszybz/add-dbus-entities-to-index (diff) | |
download | systemd-50018bfa84f5f0a0271e7656264d303e034dcf4d.tar.xz systemd-50018bfa84f5f0a0271e7656264d303e034dcf4d.zip |
sd-network: DHCPv4 Add support to send and receive LPR servers.
-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 | 18 | ||||
-rw-r--r-- | src/systemd/sd-dhcp-client.h | 1 | ||||
-rw-r--r-- | src/systemd/sd-dhcp-lease.h | 2 | ||||
-rw-r--r-- | src/systemd/sd-dhcp-server.h | 1 |
7 files changed, 55 insertions, 2 deletions
diff --git a/src/libsystemd-network/dhcp-lease-internal.h b/src/libsystemd-network/dhcp-lease-internal.h index 5cbebb4a34..67a77eb098 100644 --- a/src/libsystemd-network/dhcp-lease-internal.h +++ b/src/libsystemd-network/dhcp-lease-internal.h @@ -67,6 +67,9 @@ struct sd_dhcp_lease { struct in_addr *smtp_server; size_t smtp_server_size; + struct in_addr *lpr_server; + size_t lpr_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 1b42712479..a45167b198 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, *smtp_server; - unsigned n_ntp, n_dns, n_sip, n_pop3_server, n_smtp_server; + struct in_addr *ntp, *dns, *sip, *pop3_server, *smtp_server, *lpr_server; + unsigned n_ntp, n_dns, n_sip, n_pop3_server, n_smtp_server, n_lpr_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 5154af2304..abb2018810 100644 --- a/src/libsystemd-network/sd-dhcp-lease.c +++ b/src/libsystemd-network/sd-dhcp-lease.c @@ -140,6 +140,13 @@ int sd_dhcp_lease_get_servers( *addr = lease->smtp_server; return (int) lease->smtp_server_size; + case SD_DHCP_LEASE_LPR_SERVERS: + if (lease->lpr_server_size <= 0) + return -ENODATA; + + *addr = lease->lpr_server; + return (int) lease->lpr_server_size; + default: log_debug("Uknown DHCP lease info item %d.", what); return -ENXIO; @@ -161,6 +168,9 @@ int sd_dhcp_lease_get_pop3_server(sd_dhcp_lease *lease, const struct in_addr **a int sd_dhcp_lease_get_smtp_server(sd_dhcp_lease *lease, const struct in_addr **addr) { return sd_dhcp_lease_get_servers(lease, SD_DHCP_LEASE_SMTP_SERVERS, addr); } +int sd_dhcp_lease_get_lpr_servers(sd_dhcp_lease *lease, const struct in_addr **addr) { + return sd_dhcp_lease_get_servers(lease, SD_DHCP_LEASE_LPR_SERVERS, addr); +} int sd_dhcp_lease_get_domainname(sd_dhcp_lease *lease, const char **domainname) { assert_return(lease, -EINVAL); @@ -314,6 +324,7 @@ static sd_dhcp_lease *dhcp_lease_free(sd_dhcp_lease *lease) { free(lease->sip); free(lease->pop3_server); free(lease->smtp_server); + free(lease->lpr_server); free(lease->static_route); free(lease->client_id); free(lease->vendor_specific); @@ -648,6 +659,12 @@ int dhcp_lease_parse_options(uint8_t code, uint8_t len, const void *option, void log_debug_errno(r, "Failed to parse SMTP server, ignoring: %m"); break; + case SD_DHCP_OPTION_LPR_SERVER: + r = lease_parse_in_addrs(option, len, &lease->lpr_server, &lease->lpr_server_size); + if (r < 0) + log_debug_errno(r, "Failed to parse LPR 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) @@ -1086,6 +1103,7 @@ int dhcp_lease_load(sd_dhcp_lease **ret, const char *lease_file) { *sip = NULL, *pop3_server = NULL, *smtp_server = NULL, + *lpr_server = NULL, *mtu = NULL, *routes = NULL, *domains = NULL, @@ -1117,6 +1135,7 @@ int dhcp_lease_load(sd_dhcp_lease **ret, const char *lease_file) { "SIP", &sip, "POP3_SERVERS", &pop3_server, "SMTP_SERVERS", &smtp_server, + "LPR_SERVERS", &lpr_server, "MTU", &mtu, "DOMAINNAME", &lease->domainname, "HOSTNAME", &lease->hostname, @@ -1245,6 +1264,15 @@ int dhcp_lease_load(sd_dhcp_lease **ret, const char *lease_file) { lease->smtp_server_size = r; } + if (lpr_server) { + r = deserialize_in_addrs(&lease->lpr_server, lpr_server); + if (r < 0) + log_debug_errno(r, "Failed to deserialize LPR server %s, ignoring: %m", lpr_server); + else + lease->lpr_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 a4dcddd95d..e197f1ea72 100644 --- a/src/libsystemd-network/sd-dhcp-server.c +++ b/src/libsystemd-network/sd-dhcp-server.c @@ -142,6 +142,7 @@ static sd_dhcp_server *dhcp_server_free(sd_dhcp_server *server) { free(server->sip); free(server->pop3_server); free(server->smtp_server); + free(server->lpr_server); hashmap_free(server->leases_by_client_id); @@ -533,6 +534,15 @@ static int server_send_ack(sd_dhcp_server *server, DHCPRequest *req, return r; } + if (server->n_lpr_server > 0) { + r = dhcp_option_append( + &packet->dhcp, req->max_optlen, &offset, 0, + SD_DHCP_OPTION_LPR_SERVER, + sizeof(struct in_addr) * server->n_lpr_server, server->lpr_server); + if (r < 0) + return r; + } + if (server->timezone) { r = dhcp_option_append( &packet->dhcp, req->max_optlen, &offset, 0, @@ -1161,6 +1171,11 @@ int sd_dhcp_server_set_servers( n_a = &server->n_smtp_server; break; + case SD_DHCP_LEASE_LPR_SERVERS: + a = &server->lpr_server; + n_a = &server->n_lpr_server; + break; + default: log_debug("Uknown DHCP lease info item %d.", what); return -ENXIO; @@ -1199,6 +1214,9 @@ int sd_dhcp_server_set_pop3_server(sd_dhcp_server *server, const struct in_addr int sd_dhcp_server_set_smtp_server(sd_dhcp_server *server, const struct in_addr smtp[], unsigned n) { return sd_dhcp_server_set_servers(server, SD_DHCP_LEASE_SMTP_SERVERS, smtp, n); } +int sd_dhcp_server_set_lpr(sd_dhcp_server *server, const struct in_addr lpr[], unsigned n) { + return sd_dhcp_server_set_servers(server, SD_DHCP_LEASE_LPR_SERVERS, lpr, n); +} 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 da2aa6c73b..032afc9f12 100644 --- a/src/systemd/sd-dhcp-client.h +++ b/src/systemd/sd-dhcp-client.h @@ -48,6 +48,7 @@ enum { SD_DHCP_OPTION_TIME_OFFSET = 2, SD_DHCP_OPTION_ROUTER = 3, SD_DHCP_OPTION_DOMAIN_NAME_SERVER = 6, + SD_DHCP_OPTION_LPR_SERVER = 9, SD_DHCP_OPTION_HOST_NAME = 12, SD_DHCP_OPTION_BOOT_FILE_SIZE = 13, SD_DHCP_OPTION_DOMAIN_NAME = 15, diff --git a/src/systemd/sd-dhcp-lease.h b/src/systemd/sd-dhcp-lease.h index 70544e13f1..a3964d5989 100644 --- a/src/systemd/sd-dhcp-lease.h +++ b/src/systemd/sd-dhcp-lease.h @@ -39,6 +39,7 @@ typedef enum sd_dhcp_lease_info { SD_DHCP_LEASE_SIP_SERVERS, SD_DHCP_LEASE_POP3_SERVERS, SD_DHCP_LEASE_SMTP_SERVERS, + SD_DHCP_LEASE_LPR_SERVERS, _SD_DHCP_LEASE_INFO_MAX, } sd_dhcp_lease_info; @@ -57,6 +58,7 @@ 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_smtp_server(sd_dhcp_lease *lease, const struct in_addr **addr); +int sd_dhcp_lease_get_lpr_servers(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 4c7938ca70..017d2d9cbb 100644 --- a/src/systemd/sd-dhcp-server.h +++ b/src/systemd/sd-dhcp-server.h @@ -56,6 +56,7 @@ int sd_dhcp_server_set_servers( const struct in_addr addresses[], unsigned n_addresses); +int sd_dhcp_server_set_lpr(sd_dhcp_server *server, const struct in_addr lpr[], unsigned n); 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); |