summary refs log tree commit diff
path: root/shared/n-dhcp4/src
diff options
context:
space:
mode:
Diffstat (limited to 'shared/n-dhcp4/src')
-rw-r--r--shared/n-dhcp4/src/n-dhcp4-c-connection.c2
-rw-r--r--shared/n-dhcp4/src/n-dhcp4-c-lease.c34
-rw-r--r--shared/n-dhcp4/src/n-dhcp4-c-probe.c18
-rw-r--r--shared/n-dhcp4/src/n-dhcp4-client.c8
-rw-r--r--shared/n-dhcp4/src/n-dhcp4-private.h2
-rw-r--r--shared/n-dhcp4/src/n-dhcp4-socket.c8
-rw-r--r--shared/n-dhcp4/src/n-dhcp4.h1
-rw-r--r--shared/n-dhcp4/src/util/packet.c2
8 files changed, 47 insertions, 28 deletions
diff --git a/shared/n-dhcp4/src/n-dhcp4-c-connection.c b/shared/n-dhcp4/src/n-dhcp4-c-connection.c
index 701df1f6..31235253 100644
--- a/shared/n-dhcp4/src/n-dhcp4-c-connection.c
+++ b/shared/n-dhcp4/src/n-dhcp4-c-connection.c
@@ -1231,7 +1231,7 @@ int n_dhcp4_c_connection_dispatch_io(NDhcp4CConnection *connection,
                 /*
                  * Remember the start time of the transaction, and the base
                  * time of any relative timestamps from the pending request.
-                 * Thes same times applies to the response, and sholud be
+                 * The same time applies to the response, and should be
                  * copied over.
                  */
                 message->userdata.start_time = connection->request->userdata.start_time;
diff --git a/shared/n-dhcp4/src/n-dhcp4-c-lease.c b/shared/n-dhcp4/src/n-dhcp4-c-lease.c
index 695a112a..515814d4 100644
--- a/shared/n-dhcp4/src/n-dhcp4-c-lease.c
+++ b/shared/n-dhcp4/src/n-dhcp4-c-lease.c
@@ -2,7 +2,7 @@
  * DHCP4 Client Leases
  *
  * This implements the public API wrapping DHCP4 client leases. A lease object
- * conists of the information given to us from the server, together with the
+ * consists of the information given to us from the server, together with the
  * timestamp recording the start of the validity of the lease.
  *
  * A probe may yield many OFFERS, each of which contains a lease object. One of
@@ -98,7 +98,7 @@ static int n_dhcp4_incoming_get_timeouts(NDhcp4Incoming *message, uint64_t *t1p,
 
 /**
  * n_dhcp4_client_lease_new() - allocate new client lease object
- * @leasep:                     output argumnet for new client lease object
+ * @leasep:                     output argument for new client lease object
  * @message:                    incoming message representing the lease
  *
  * This creates a new client lease object. Client lease objects are simple
@@ -194,7 +194,7 @@ void n_dhcp4_client_lease_unlink(NDhcp4ClientLease *lease) {
  * @lease:                      the lease to operate on
  * @yiaddr:                     return argument for the IP address
  *
- * Gets the IP address cotained in the lease. Or INADDR_ANY if the lease
+ * Gets the IP address contained in the lease. Or INADDR_ANY if the lease
  * does not contain an IP address.
  */
 _c_public_ void n_dhcp4_client_lease_get_yiaddr(NDhcp4ClientLease *lease, struct in_addr *yiaddr) {
@@ -208,7 +208,7 @@ _c_public_ void n_dhcp4_client_lease_get_yiaddr(NDhcp4ClientLease *lease, struct
  * @lease:                      the lease to operate on
  * @siaddr:                     return argument for the IP address
  *
- * Gets the server IP address cotained in the lease. Or INADDR_ANY if the
+ * Gets the server IP address contained in the lease. Or INADDR_ANY if the
  * lease does not contain an IP address.
  */
 _c_public_ void n_dhcp4_client_lease_get_siaddr(NDhcp4ClientLease *lease, struct in_addr *siaddr) {
@@ -242,6 +242,32 @@ _c_public_ void n_dhcp4_client_lease_get_lifetime(NDhcp4ClientLease *lease, uint
 }
 
 /**
+ * n_dhcp4_client_lease_get_server_identifier() - get the server identifier
+ * @lease:                      the lease to operate on
+ * @addr:                       return argument for the server identifier
+ *
+ * Gets the address contained in the server-identifier DHCP option, in network
+ * byte order.
+ *
+ * Return: 0 on success, negative error code on failure.
+ */
+_c_public_ int n_dhcp4_client_lease_get_server_identifier (NDhcp4ClientLease *lease, struct in_addr *addr) {
+        uint8_t *data;
+        size_t n_data;
+        int r;
+
+        r = n_dhcp4_incoming_query(lease->message, N_DHCP4_OPTION_SERVER_IDENTIFIER, &data, &n_data);
+        if (r)
+                return r;
+        if (n_data < sizeof(struct in_addr))
+                return N_DHCP4_E_MALFORMED;
+
+        memcpy(addr, data, sizeof(struct in_addr));
+
+        return 0;
+}
+
+/**
  * n_dhcp4_client_lease_query() - query the lease for an option
  * @lease:                      the lease to operate on
  * @option:                     the DHCP4 option code
diff --git a/shared/n-dhcp4/src/n-dhcp4-c-probe.c b/shared/n-dhcp4/src/n-dhcp4-c-probe.c
index f3d4f265..7f20ac05 100644
--- a/shared/n-dhcp4/src/n-dhcp4-c-probe.c
+++ b/shared/n-dhcp4/src/n-dhcp4-c-probe.c
@@ -221,7 +221,7 @@ _c_public_ void n_dhcp4_client_probe_config_set_requested_ip(NDhcp4ClientProbeCo
  * delay is specified to be a random value in the range 1000 to 10.000 ms.
  * However, there does not appear to be any particular reason to
  * unconditionally wait at least one second, so we move the range down to
- * start at 0 ms. The reaon for the random delay is to avoid network-wide
+ * start at 0 ms. The reason for the random delay is to avoid network-wide
  * events causing too much simultaneous network traffic. However, on modern
  * networks, a more reasonable value may be in the 10 ms range.
  */
@@ -236,7 +236,7 @@ _c_public_ void n_dhcp4_client_probe_config_set_start_delay(NDhcp4ClientProbeCon
  *
  * This adds an option to the list of options to request from the server.
  *
- * A server may send options that we do not requst, and it may omit options
+ * A server may send options that we do not request, and it may omit options
  * that we do request. However, to increase the likelyhood of uniform behavior
  * between server implementations, we do not expose options that were not
  * explicitly requested.
@@ -316,10 +316,9 @@ static void n_dhcp4_client_probe_config_initialize_random_seed(NDhcp4ClientProbe
         unsigned short int seed16v[3];
         const uint8_t *p;
         uint64_t u64;
-        int r;
 
         /*
-         * Initialize seed48_r(3)
+         * Initialize config's entropy buffer for successive jrand48(3) calls.
          *
          * We need random jitter for all timeouts and delays, used to reduce
          * network traffic during bursts. This is not meant as security measure
@@ -360,8 +359,7 @@ static void n_dhcp4_client_probe_config_initialize_random_seed(NDhcp4ClientProbe
         seed16v[1] = (u64 >> 16) ^ (u64 >>  0);
         seed16v[2] = (u64 >> 32) ^ (u64 >> 16);
 
-        r = seed48_r(seed16v, &config->entropy);
-        c_assert(!r);
+        memcpy(config->entropy, seed16v, sizeof(seed16v));
 }
 
 /**
@@ -374,13 +372,7 @@ static void n_dhcp4_client_probe_config_initialize_random_seed(NDhcp4ClientProbe
  * Return: the random data.
  */
 uint32_t n_dhcp4_client_probe_config_get_random(NDhcp4ClientProbeConfig *config) {
-        long int result;
-        int r;
-
-        r = mrand48_r(&config->entropy, &result);
-        c_assert(!r);
-
-        return result;
+        return jrand48(config->entropy);
 };
 
 /**
diff --git a/shared/n-dhcp4/src/n-dhcp4-client.c b/shared/n-dhcp4/src/n-dhcp4-client.c
index 403a6932..1dedbf30 100644
--- a/shared/n-dhcp4/src/n-dhcp4-client.c
+++ b/shared/n-dhcp4/src/n-dhcp4-client.c
@@ -146,14 +146,14 @@ _c_public_ void n_dhcp4_client_config_set_transport(NDhcp4ClientConfig *config,
  *
  * Background: OFFER and ACK messages from DHCP servers to clients are unicast
  *             to the IP address handed out, even before the IP address has
- *             been configured on the taregt interface. This usually works
+ *             been configured on the target interface. This usually works
  *             because the correct destination hardware address is explicitly
  *             set on the outgoing packets, rather than being resolved (which
  *             would not work). However, some hardware does not accept incoming
  *             IP packets destined for addresses they do not own, even if the
  *             hardware address is correct. In this case, the server must
  *             broadcast the replies in order for the client to receive them.
- *             In general, unneccesary broadcasting is something one wants to
+ *             In general, unnecessary broadcasting is something one wants to
  *             avoid, and some networks will not deliver broadcasts to the
  *             client at all, in which case this flag must not be set.
  */
@@ -549,7 +549,7 @@ void n_dhcp4_log_queue_fmt(NDhcp4LogQueue *log_queue,
         if (level > log_queue->log_level)
                 return;
 
-        /* Currently the logging queue is only implemented for
+        /* Currently, the logging queue is only implemented for
          * the client. Nobody would enable logging except a
          * client instance. */
         c_assert(log_queue->is_client);
@@ -953,7 +953,7 @@ _c_public_ int n_dhcp4_client_update_mtu(NDhcp4Client *client, uint16_t mtu) {
  * This creates a new probe on @client. Probes represent DHCP requests and
  * track the state over the entire lifetime of a lease. Once a probe is created
  * it will start looking for DHCP servers, request a lease from them, and renew
- * the lease continously whenever it expires. Furthermore, if a lease cannot be
+ * the lease continuously whenever it expires. Furthermore, if a lease cannot be
  * renewed, a new lease will be requested.
  *
  * The API allows for many probes to be run at the same time. However, the DHCP
diff --git a/shared/n-dhcp4/src/n-dhcp4-private.h b/shared/n-dhcp4/src/n-dhcp4-private.h
index 90f8f0c3..db7b24ff 100644
--- a/shared/n-dhcp4/src/n-dhcp4-private.h
+++ b/shared/n-dhcp4/src/n-dhcp4-private.h
@@ -263,7 +263,7 @@ struct NDhcp4ClientProbeConfig {
         bool inform_only;
         bool init_reboot;
         struct in_addr requested_ip;
-        struct drand48_data entropy;    /* entropy pool */
+        unsigned short int entropy[3];
         uint64_t ms_start_delay;        /* max ms to wait before starting probe */
         NDhcp4ClientProbeOption *options[UINT8_MAX + 1];
         int8_t request_parameters[UINT8_MAX + 1];
diff --git a/shared/n-dhcp4/src/n-dhcp4-socket.c b/shared/n-dhcp4/src/n-dhcp4-socket.c
index 7291c780..3e703b4f 100644
--- a/shared/n-dhcp4/src/n-dhcp4-socket.c
+++ b/shared/n-dhcp4/src/n-dhcp4-socket.c
@@ -22,7 +22,7 @@
 
 /**
  * n_dhcp4_c_socket_packet_new() - create a new DHCP4 client packet socket
- * @sockfdp:            return argumnet for the new socket
+ * @sockfdp:            return argument for the new socket
  * @ifindex:            interface index to bind to
  *
  * Create a new AF_PACKET/SOCK_DGRAM socket usable to listen to and send DHCP client
@@ -129,7 +129,7 @@ int n_dhcp4_c_socket_packet_new(int *sockfdp, int ifindex) {
 
 /**
  * n_dhcp4_c_socket_udp_new() - create a new DHCP4 client UDP socket
- * @sockfdp:            return argumnet for the new socket
+ * @sockfdp:            return argument for the new socket
  * @ifindex:            interface index to bind to
  * @client_addr:        client address to bind to
  * @server_addr:        server address to connect to
@@ -230,7 +230,7 @@ int n_dhcp4_c_socket_udp_new(int *sockfdp,
 
 /**
  * n_dhcp4_s_socket_packet_new() - create a new DHCP4 server packet socket
- * @sockfdp:            return argumnet for the new socket
+ * @sockfdp:            return argument for the new socket
  *
  * Create a new AF_PACKET/SOCK_DGRAM socket usable to send DHCP packets to clients
  * before they have an IP address configured, on the given interface.
@@ -251,7 +251,7 @@ int n_dhcp4_s_socket_packet_new(int *sockfdp) {
 
 /**
  * n_dhcp4_s_socket_udp_new() - create a new DHCP4 server UDP socket
- * @sockfdp:            return argumnet for the new socket
+ * @sockfdp:            return argument for the new socket
  * @ifindex:            intercafe index to bind to
  *
  * Create a new AF_INET/SOCK_DGRAM socket usable to listen to DHCP server packets,
diff --git a/shared/n-dhcp4/src/n-dhcp4.h b/shared/n-dhcp4/src/n-dhcp4.h
index 81452848..435c5600 100644
--- a/shared/n-dhcp4/src/n-dhcp4.h
+++ b/shared/n-dhcp4/src/n-dhcp4.h
@@ -171,6 +171,7 @@ void n_dhcp4_client_lease_get_siaddr(NDhcp4ClientLease *lease, struct in_addr *s
 void n_dhcp4_client_lease_get_basetime(NDhcp4ClientLease *lease, uint64_t *ns_basetimep);
 void n_dhcp4_client_lease_get_lifetime(NDhcp4ClientLease *lease, uint64_t *ns_lifetimep);
 int n_dhcp4_client_lease_query(NDhcp4ClientLease *lease, uint8_t option, uint8_t **datap, size_t *n_datap);
+int n_dhcp4_client_lease_get_server_identifier (NDhcp4ClientLease *lease, struct in_addr *addr);
 
 int n_dhcp4_client_lease_select(NDhcp4ClientLease *lease);
 int n_dhcp4_client_lease_accept(NDhcp4ClientLease *lease);
diff --git a/shared/n-dhcp4/src/util/packet.c b/shared/n-dhcp4/src/util/packet.c
index 95e65940..ef18b0b4 100644
--- a/shared/n-dhcp4/src/util/packet.c
+++ b/shared/n-dhcp4/src/util/packet.c
@@ -244,7 +244,7 @@ int packet_sendto_udp(int sockfd,
  * @buf:                buffor for payload
  * @n_buf:              max length of payload in bytes
  * @n_transmittedp:     output argument for number transmitted bytes
- * @src:                return argumnet for source address, or NULL, see ip(7)
+ * @src:                return argument for source address, or NULL, see ip(7)
  *
  * Receives an UDP packet on a AF_PACKET socket. The difference between
  * this and recvfrom() on an AF_INET socket is that the packet will be