diff options
Diffstat (limited to 'networking/udhcp/files.c')
-rw-r--r-- | networking/udhcp/files.c | 48 |
1 files changed, 47 insertions, 1 deletions
diff --git a/networking/udhcp/files.c b/networking/udhcp/files.c index 73a3bbc6e..33cd25aff 100644 --- a/networking/udhcp/files.c +++ b/networking/udhcp/files.c | |||
@@ -15,8 +15,8 @@ | |||
15 | #include "static_leases.h" | 15 | #include "static_leases.h" |
16 | 16 | ||
17 | #include "dhcpd.h" | 17 | #include "dhcpd.h" |
18 | #include "files.h" | ||
19 | #include "options.h" | 18 | #include "options.h" |
19 | #include "files.h" | ||
20 | #include "common.h" | 20 | #include "common.h" |
21 | 21 | ||
22 | /* | 22 | /* |
@@ -93,6 +93,52 @@ static int read_yn(const char *line, void *arg) | |||
93 | } | 93 | } |
94 | 94 | ||
95 | 95 | ||
96 | /* find option 'code' in opt_list */ | ||
97 | struct option_set *find_option(struct option_set *opt_list, char code) | ||
98 | { | ||
99 | while (opt_list && opt_list->data[OPT_CODE] < code) | ||
100 | opt_list = opt_list->next; | ||
101 | |||
102 | if (opt_list && opt_list->data[OPT_CODE] == code) return opt_list; | ||
103 | else return NULL; | ||
104 | } | ||
105 | |||
106 | |||
107 | /* add an option to the opt_list */ | ||
108 | void attach_option(struct option_set **opt_list, struct dhcp_option *option, char *buffer, int length) | ||
109 | { | ||
110 | struct option_set *existing, *new, **curr; | ||
111 | |||
112 | /* add it to an existing option */ | ||
113 | if ((existing = find_option(*opt_list, option->code))) { | ||
114 | DEBUG(LOG_INFO, "Attaching option %s to existing member of list", option->name); | ||
115 | if (option->flags & OPTION_LIST) { | ||
116 | if (existing->data[OPT_LEN] + length <= 255) { | ||
117 | existing->data = realloc(existing->data, | ||
118 | existing->data[OPT_LEN] + length + 2); | ||
119 | memcpy(existing->data + existing->data[OPT_LEN] + 2, buffer, length); | ||
120 | existing->data[OPT_LEN] += length; | ||
121 | } /* else, ignore the data, we could put this in a second option in the future */ | ||
122 | } /* else, ignore the new data */ | ||
123 | } else { | ||
124 | DEBUG(LOG_INFO, "Attaching option %s to list", option->name); | ||
125 | |||
126 | /* make a new option */ | ||
127 | new = xmalloc(sizeof(struct option_set)); | ||
128 | new->data = xmalloc(length + 2); | ||
129 | new->data[OPT_CODE] = option->code; | ||
130 | new->data[OPT_LEN] = length; | ||
131 | memcpy(new->data + 2, buffer, length); | ||
132 | |||
133 | curr = opt_list; | ||
134 | while (*curr && (*curr)->data[OPT_CODE] < option->code) | ||
135 | curr = &(*curr)->next; | ||
136 | |||
137 | new->next = *curr; | ||
138 | *curr = new; | ||
139 | } | ||
140 | } | ||
141 | |||
96 | /* read a dhcp option and add it to opt_list */ | 142 | /* read a dhcp option and add it to opt_list */ |
97 | static int read_opt(const char *const_line, void *arg) | 143 | static int read_opt(const char *const_line, void *arg) |
98 | { | 144 | { |