]> git.ipfire.org Git - thirdparty/systemd.git/blobdiff - src/libsystemd-network/dhcp-option.c
Add SPDX license identifiers to source files under the LGPL
[thirdparty/systemd.git] / src / libsystemd-network / dhcp-option.c
index 1de7f3639cbca8e73ed849b43a157f8e54def2d6..19fc525866b213f8cf4b8c04522c646caa1eb06c 100644 (file)
@@ -1,5 +1,4 @@
-/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
-
+/* SPDX-License-Identifier: LGPL-2.1+ */
 /***
   This file is part of systemd.
 
@@ -34,14 +33,14 @@ static int option_append(uint8_t options[], size_t size, size_t *offset,
         assert(options);
         assert(offset);
 
-        if (code != DHCP_OPTION_END)
+        if (code != SD_DHCP_OPTION_END)
                 /* always make sure there is space for an END option */
-                size --;
+                size--;
 
         switch (code) {
 
-        case DHCP_OPTION_PAD:
-        case DHCP_OPTION_END:
+        case SD_DHCP_OPTION_PAD:
+        case SD_DHCP_OPTION_END:
                 if (size < *offset + 1)
                         return -ENOBUFS;
 
@@ -56,12 +55,7 @@ static int option_append(uint8_t options[], size_t size, size_t *offset,
                 options[*offset] = code;
                 options[*offset + 1] = optlen;
 
-                if (optlen) {
-                        assert(optval);
-
-                        memcpy(&options[*offset + 2], optval, optlen);
-                }
-
+                memcpy_safe(&options[*offset + 2], optval, optlen);
                 *offset += optlen + 2;
 
                 break;
@@ -91,7 +85,7 @@ int dhcp_option_append(DHCPMessage *message, size_t size, size_t *offset,
                 else if (r == -ENOBUFS && (file || sname)) {
                         /* did not fit, but we have more buffers to try
                            close the options array and move the offset to its end */
-                        r = option_append(message->options, size, offset, DHCP_OPTION_END, 0, NULL);
+                        r = option_append(message->options, size, offset, SD_DHCP_OPTION_END, 0, NULL);
                         if (r < 0)
                                 return r;
 
@@ -112,7 +106,7 @@ int dhcp_option_append(DHCPMessage *message, size_t size, size_t *offset,
                         } else if (r == -ENOBUFS && sname) {
                                 /* did not fit, but we have more buffers to try
                                    close the file array and move the offset to its end */
-                                r = option_append(message->options, size, offset, DHCP_OPTION_END, 0, NULL);
+                                r = option_append(message->options, size, offset, SD_DHCP_OPTION_END, 0, NULL);
                                 if (r < 0)
                                         return r;
 
@@ -142,7 +136,7 @@ int dhcp_option_append(DHCPMessage *message, size_t size, size_t *offset,
 }
 
 static int parse_options(const uint8_t options[], size_t buflen, uint8_t *overload,
-                         uint8_t *message_type, char **error_message, dhcp_option_cb_t cb,
+                         uint8_t *message_type, char **error_message, dhcp_option_callback_t cb,
                          void *userdata) {
         uint8_t code, len;
         const uint8_t *option;
@@ -152,10 +146,10 @@ static int parse_options(const uint8_t options[], size_t buflen, uint8_t *overlo
                 code = options[offset ++];
 
                 switch (code) {
-                case DHCP_OPTION_PAD:
+                case SD_DHCP_OPTION_PAD:
                         continue;
 
-                case DHCP_OPTION_END:
+                case SD_DHCP_OPTION_END:
                         return 0;
                 }
 
@@ -170,7 +164,7 @@ static int parse_options(const uint8_t options[], size_t buflen, uint8_t *overlo
                 option = &options[offset];
 
                 switch (code) {
-                case DHCP_OPTION_MESSAGE_TYPE:
+                case SD_DHCP_OPTION_MESSAGE_TYPE:
                         if (len != 1)
                                 return -EINVAL;
 
@@ -179,7 +173,7 @@ static int parse_options(const uint8_t options[], size_t buflen, uint8_t *overlo
 
                         break;
 
-                case DHCP_OPTION_ERROR_MESSAGE:
+                case SD_DHCP_OPTION_ERROR_MESSAGE:
                         if (len == 0)
                                 return -EINVAL;
 
@@ -203,7 +197,7 @@ static int parse_options(const uint8_t options[], size_t buflen, uint8_t *overlo
                         }
 
                         break;
-                case DHCP_OPTION_OVERLOAD:
+                case SD_DHCP_OPTION_OVERLOAD:
                         if (len != 1)
                                 return -EINVAL;
 
@@ -228,7 +222,7 @@ static int parse_options(const uint8_t options[], size_t buflen, uint8_t *overlo
         return 0;
 }
 
-int dhcp_option_parse(DHCPMessage *message, size_t len, dhcp_option_cb_t cb, void *userdata, char **_error_message) {
+int dhcp_option_parse(DHCPMessage *message, size_t len, dhcp_option_callback_t cb, void *userdata, char **_error_message) {
         _cleanup_free_ char *error_message = NULL;
         uint8_t overload = 0;
         uint8_t message_type = 0;