/***
This file is part of systemd.
Copyright (C) 2013 Intel Corporation. All rights reserved.
under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation; either version 2.1 of the License, or
(at your option) any later version.
systemd is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with systemd; If not, see <http://www.gnu.org/licenses/>.
***/
#include <errno.h>
#include <stdint.h>
#include <stdio.h>
#include <string.h>
#include "alloc-util.h"
#include "utf8.h"
#include "dhcp-internal.h"
if (code != SD_DHCP_OPTION_END)
/* always make sure there is space for an END option */
size --;
switch (code) {
case SD_DHCP_OPTION_PAD:
case SD_DHCP_OPTION_END:
return -ENOBUFS;
*offset += 1;
break;
default:
return -ENOBUFS;
if (optlen) {
}
break;
}
return 0;
}
int r;
/* still space in the options array */
if (r >= 0)
return 0;
/* did not fit, but we have more buffers to try
close the options array and move the offset to its end */
if (r < 0)
return r;
} else
return r;
}
if (overload & DHCP_OVERLOAD_FILE) {
/* still space in the 'file' array */
if (r >= 0) {
return 0;
/* did not fit, but we have more buffers to try
close the file array and move the offset to its end */
if (r < 0)
return r;
} else
return r;
}
}
if (overload & DHCP_OVERLOAD_SNAME) {
/* still space in the 'sname' array */
if (r >= 0) {
return 0;
} else {
/* no space, or other error, give up */
return r;
}
}
}
return -ENOBUFS;
}
void *userdata) {
switch (code) {
case SD_DHCP_OPTION_PAD:
continue;
case SD_DHCP_OPTION_END:
return 0;
}
return -ENOBUFS;
return -EINVAL;
switch (code) {
if (len != 1)
return -EINVAL;
if (message_type)
*message_type = *option;
break;
if (len == 0)
return -EINVAL;
if (error_message) {
/* Accept a trailing NUL byte */
return -EINVAL;
if (!string)
return -ENOMEM;
if (!ascii_is_valid(string))
return -EINVAL;
*error_message = string;
}
break;
case SD_DHCP_OPTION_OVERLOAD:
if (len != 1)
return -EINVAL;
if (overload)
break;
default:
if (cb)
break;
}
}
return -EINVAL;
return 0;
}
int dhcp_option_parse(DHCPMessage *message, size_t len, dhcp_option_cb_t cb, void *userdata, char **_error_message) {
int r;
if (!message)
return -EINVAL;
if (len < sizeof(DHCPMessage))
return -EINVAL;
len -= sizeof(DHCPMessage);
if (r < 0)
return r;
if (overload & DHCP_OVERLOAD_FILE) {
r = parse_options(message->file, sizeof(message->file), NULL, &message_type, &error_message, cb, userdata);
if (r < 0)
return r;
}
if (overload & DHCP_OVERLOAD_SNAME) {
r = parse_options(message->sname, sizeof(message->sname), NULL, &message_type, &error_message, cb, userdata);
if (r < 0)
return r;
}
if (message_type == 0)
return -ENOMSG;
}
return message_type;
}