mirror of
https://github.com/systemd/systemd.git
synced 2024-12-25 01:34:28 +03:00
sd-dhcp-lease: add NTP support
Export the NTP servers so timesyncd can use them.
This commit is contained in:
parent
39594d49cf
commit
4684469639
@ -44,6 +44,8 @@ struct sd_dhcp_lease {
|
|||||||
be32_t next_server;
|
be32_t next_server;
|
||||||
struct in_addr *dns;
|
struct in_addr *dns;
|
||||||
size_t dns_size;
|
size_t dns_size;
|
||||||
|
struct in_addr *ntp;
|
||||||
|
size_t ntp_size;
|
||||||
uint16_t mtu;
|
uint16_t mtu;
|
||||||
char *domainname;
|
char *domainname;
|
||||||
char *hostname;
|
char *hostname;
|
||||||
|
@ -72,6 +72,20 @@ int sd_dhcp_lease_get_dns(sd_dhcp_lease *lease, struct in_addr **addr, size_t *a
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int sd_dhcp_lease_get_ntp(sd_dhcp_lease *lease, struct in_addr **addr, size_t *addr_size) {
|
||||||
|
assert_return(lease, -EINVAL);
|
||||||
|
assert_return(addr, -EINVAL);
|
||||||
|
assert_return(addr_size, -EINVAL);
|
||||||
|
|
||||||
|
if (lease->ntp_size) {
|
||||||
|
*addr_size = lease->ntp_size;
|
||||||
|
*addr = lease->ntp;
|
||||||
|
} else
|
||||||
|
return -ENOENT;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
int sd_dhcp_lease_get_domainname(sd_dhcp_lease *lease, const char **domainname) {
|
int sd_dhcp_lease_get_domainname(sd_dhcp_lease *lease, const char **domainname) {
|
||||||
assert_return(lease, -EINVAL);
|
assert_return(lease, -EINVAL);
|
||||||
assert_return(domainname, -EINVAL);
|
assert_return(domainname, -EINVAL);
|
||||||
@ -213,6 +227,24 @@ int dhcp_lease_parse_options(uint8_t code, uint8_t len, const uint8_t *option,
|
|||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case DHCP_OPTION_NTP_SERVER:
|
||||||
|
if (len && !(len % 4)) {
|
||||||
|
unsigned i;
|
||||||
|
|
||||||
|
lease->ntp_size = len / 4;
|
||||||
|
|
||||||
|
free(lease->ntp);
|
||||||
|
lease->ntp = new0(struct in_addr, lease->ntp_size);
|
||||||
|
if (!lease->ntp)
|
||||||
|
return -ENOMEM;
|
||||||
|
|
||||||
|
for (i = 0; i < lease->ntp_size; i++) {
|
||||||
|
memcpy(&lease->ntp[i].s_addr, option + 4 * i, 4);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
|
||||||
case DHCP_OPTION_INTERFACE_MTU:
|
case DHCP_OPTION_INTERFACE_MTU:
|
||||||
if (len >= 2) {
|
if (len >= 2) {
|
||||||
be16_t mtu;
|
be16_t mtu;
|
||||||
|
@ -36,6 +36,7 @@ int sd_dhcp_lease_get_router(sd_dhcp_lease *lease, struct in_addr *addr);
|
|||||||
int sd_dhcp_lease_get_next_server(sd_dhcp_lease *lease, struct in_addr *addr);
|
int sd_dhcp_lease_get_next_server(sd_dhcp_lease *lease, struct in_addr *addr);
|
||||||
int sd_dhcp_lease_get_server_identifier(sd_dhcp_lease *lease, struct in_addr *addr);
|
int sd_dhcp_lease_get_server_identifier(sd_dhcp_lease *lease, struct in_addr *addr);
|
||||||
int sd_dhcp_lease_get_dns(sd_dhcp_lease *lease, struct in_addr **addr, size_t *addr_size);
|
int sd_dhcp_lease_get_dns(sd_dhcp_lease *lease, struct in_addr **addr, size_t *addr_size);
|
||||||
|
int sd_dhcp_lease_get_ntp(sd_dhcp_lease *lease, struct in_addr **addr, size_t *addr_size);
|
||||||
int sd_dhcp_lease_get_mtu(sd_dhcp_lease *lease, uint16_t *mtu);
|
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_domainname(sd_dhcp_lease *lease, const char **domainname);
|
||||||
int sd_dhcp_lease_get_hostname(sd_dhcp_lease *lease, const char **hostname);
|
int sd_dhcp_lease_get_hostname(sd_dhcp_lease *lease, const char **hostname);
|
||||||
|
Loading…
Reference in New Issue
Block a user