summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSascha Hauer <s.hauer@pengutronix.de>2016-01-11 13:11:07 +0100
committerSascha Hauer <s.hauer@pengutronix.de>2016-01-11 13:11:07 +0100
commite64f16cf34175d9e662edfaa02bc7895c1b50b96 (patch)
tree98b2387b169376b005f671635cfb953dbe675851
parent2881f2df35d15754874e90be112d67f33088326f (diff)
parent39698df6f7623fca8f6bdb500625e8da2fcd54f5 (diff)
downloadbarebox-e64f16cf34175d9e662edfaa02bc7895c1b50b96.tar.gz
barebox-e64f16cf34175d9e662edfaa02bc7895c1b50b96.tar.xz
Merge branch 'for-next/net'
-rw-r--r--include/net.h4
-rw-r--r--net/dhcp.c149
-rw-r--r--net/dns.c4
3 files changed, 67 insertions, 90 deletions
diff --git a/include/net.h b/include/net.h
index 2a37a43a5c..13e335aac2 100644
--- a/include/net.h
+++ b/include/net.h
@@ -315,9 +315,9 @@ int string_to_ethaddr(const char *str, u8 enetaddr[6]);
void ethaddr_to_string(const u8 enetaddr[6], char *str);
#ifdef CONFIG_NET_RESOLV
-IPaddr_t resolv(char *host);
+IPaddr_t resolv(const char *host);
#else
-static inline IPaddr_t resolv(char *host)
+static inline IPaddr_t resolv(const char *host)
{
IPaddr_t ip = 0;
string_to_ip(host, &ip);
diff --git a/net/dhcp.c b/net/dhcp.c
index fb8a7133c1..4433b442db 100644
--- a/net/dhcp.c
+++ b/net/dhcp.c
@@ -115,6 +115,7 @@ struct dhcp_opt {
const char *barebox_var_name;
const char *barebox_dhcp_global;
void (*handle)(struct dhcp_opt *opt, unsigned char *data, int tlen);
+ int (*handle_param)(struct dhcp_opt *dhcp_opt, u8 *e);
void *data;
struct bootp *bp;
@@ -200,6 +201,37 @@ static void bootfile_vendorex_handle(struct dhcp_opt *opt, unsigned char *popt,
env_str_handle(opt, popt, optlen);
}
+static int dhcp_set_string_options(struct dhcp_opt *param, u8 *e)
+{
+ int str_len;
+ const char *str = param->data;
+
+ if (!str && param->barebox_var_name && IS_ENABLED(CONFIG_ENVIRONMENT_VARIABLES))
+ str = getenv(param->barebox_var_name);
+
+ if (!str && param->barebox_dhcp_global && IS_ENABLED(CONFIG_GLOBALVAR))
+ str = dhcp_get_barebox_global(param->barebox_dhcp_global);
+
+ if (!str)
+ return 0;
+
+ str_len = strlen(str);
+ if (!str_len)
+ return 0;
+
+ *e++ = param->option;
+ *e++ = str_len;
+ memcpy(e, str, str_len);
+
+ return str_len + 2;
+}
+
+#define DHCP_HOSTNAME 12
+#define DHCP_VENDOR_ID 60
+#define DHCP_CLIENT_ID 61
+#define DHCP_USER_CLASS 77
+#define DHCP_CLIENT_UUID 97
+
struct dhcp_opt dhcp_options[] = {
{
.option = 1,
@@ -212,9 +244,10 @@ struct dhcp_opt dhcp_options[] = {
.handle = env_ip_handle,
.barebox_var_name = "net.nameserver",
}, {
- .option = 12,
+ .option = DHCP_HOSTNAME,
.copy_only_if_valid = 1,
.handle = env_str_handle,
+ .handle_param = dhcp_set_string_options,
.barebox_var_name = "global.hostname",
}, {
.option = 15,
@@ -234,6 +267,10 @@ struct dhcp_opt dhcp_options[] = {
.data = &net_dhcp_server_ip,
.optional = true,
}, {
+ .option = DHCP_VENDOR_ID,
+ .handle_param = dhcp_set_string_options,
+ .barebox_dhcp_global = "vendor_id",
+ },{
.option = 66,
.handle = env_str_handle,
.barebox_dhcp_global = "tftp_server_name",
@@ -243,85 +280,34 @@ struct dhcp_opt dhcp_options[] = {
.handle = bootfile_vendorex_handle,
.barebox_dhcp_global = "bootfile",
}, {
- .option = 224,
- .handle = env_str_handle,
- .barebox_dhcp_global = "oftree_file",
- },
-};
-
-struct dhcp_param {
- unsigned char option;
- const char *barebox_var_name;
- const char *barebox_dhcp_global;
- int (*handle)(struct dhcp_param *param, u8 *e);
- void *data;
-};
-
-static int dhcp_set_string_options(struct dhcp_param *param, u8 *e)
-{
- int str_len;
- char* str = param->data;
-
- if (!str && param->barebox_var_name && IS_ENABLED(CONFIG_ENVIRONMENT_VARIABLES))
- str = (char*)getenv(param->barebox_var_name);
-
- if (!str && param->barebox_dhcp_global && IS_ENABLED(CONFIG_GLOBALVAR))
- str = (char*)dhcp_get_barebox_global(param->barebox_dhcp_global);
-
- if (!str)
- return 0;
-
- str_len = strlen(str);
- if (!str_len)
- return 0;
-
- *e++ = param->option;
- *e++ = str_len;
- memcpy(e, str, str_len);
-
- return str_len + 2;
-}
-
-#define DHCP_HOSTNAME 12
-#define DHCP_VENDOR_ID 60
-#define DHCP_CLIENT_ID 61
-#define DHCP_USER_CLASS 77
-#define DHCP_CLIENT_UUID 97
-
-struct dhcp_param dhcp_params[] = {
- {
- .option = DHCP_HOSTNAME,
- .handle = dhcp_set_string_options,
- .barebox_var_name = "global.hostname",
- }, {
- .option = DHCP_VENDOR_ID,
- .handle = dhcp_set_string_options,
- .barebox_dhcp_global = "vendor_id",
- }, {
.option = DHCP_CLIENT_ID,
- .handle = dhcp_set_string_options,
+ .handle_param = dhcp_set_string_options,
.barebox_dhcp_global = "client_id",
}, {
.option = DHCP_USER_CLASS,
- .handle = dhcp_set_string_options,
+ .handle_param = dhcp_set_string_options,
.barebox_dhcp_global = "user_class",
}, {
.option = DHCP_CLIENT_UUID,
- .handle = dhcp_set_string_options,
+ .handle_param = dhcp_set_string_options,
.barebox_dhcp_global = "client_uuid",
- }
+ }, {
+ .option = 224,
+ .handle = env_str_handle,
+ .barebox_dhcp_global = "oftree_file",
+ },
};
static void dhcp_set_param_data(int option, void* data)
{
- struct dhcp_param *param;
+ struct dhcp_opt *opt;
int i;
- for (i = 0; i < ARRAY_SIZE(dhcp_params); i++) {
- param = &dhcp_params[i];
+ for (i = 0; i < ARRAY_SIZE(dhcp_options); i++) {
+ opt = &dhcp_options[i];
- if (param->option == option) {
- param->data = data;
+ if (opt->option == option) {
+ opt->data = data;
return;
}
}
@@ -405,6 +391,7 @@ static void bootp_copy_net_params(struct bootp *bp)
static int dhcp_extended (u8 *e, int message_type, IPaddr_t ServerID,
IPaddr_t RequestedIP)
{
+ struct dhcp_opt *opt;
int i;
u8 *start = e;
u8 *cnt;
@@ -427,8 +414,11 @@ static int dhcp_extended (u8 *e, int message_type, IPaddr_t ServerID,
e += dhcp_set_ip_options(50, e, RequestedIP);
e += dhcp_set_ip_options(54, e, ServerID);
- for (i = 0; i < ARRAY_SIZE(dhcp_params); i++)
- e += dhcp_params[i].handle(&dhcp_params[i], e);
+ for (i = 0; i < ARRAY_SIZE(dhcp_options); i++) {
+ opt = &dhcp_options[i];
+ if (opt->handle_param)
+ e += opt->handle_param(opt, e);
+ }
*e++ = 55; /* Parameter Request List */
cnt = e++; /* Pointer to count of requested items */
@@ -492,7 +482,7 @@ static int bootp_request(void)
return ret;
}
-static int dhcp_options_handle(unsigned char option, unsigned char *popt,
+static void dhcp_options_handle(unsigned char option, unsigned char *popt,
int optlen, struct bootp *bp)
{
int i;
@@ -502,13 +492,13 @@ static int dhcp_options_handle(unsigned char option, unsigned char *popt,
opt = &dhcp_options[i];
if (opt->option == option) {
opt->bp = bp;
- opt->handle(opt, popt, optlen);
- goto end;
+ if (opt->handle)
+ opt->handle(opt, popt, optlen);
+ return;
}
}
-end:
- return i;
+ debug("*** Unhandled DHCP Option in OFFER/ACK: %d\n", option);
}
static void dhcp_options_process(unsigned char *popt, struct bootp *bp)
@@ -516,15 +506,12 @@ static void dhcp_options_process(unsigned char *popt, struct bootp *bp)
unsigned char *end = popt + sizeof(*bp) + OPT_SIZE;
int oplen;
unsigned char option;
- int i;
while (popt < end && *popt != 0xff) {
oplen = *(popt + 1);
option = *popt;
- i = dhcp_options_handle(option, popt + 2, oplen, bp);
- if (i == ARRAY_SIZE(dhcp_options))
- debug("*** Unhandled DHCP Option in OFFER/ACK: %d\n", option);
+ dhcp_options_handle(option, popt + 2, oplen, bp);
popt += oplen + 2; /* Process next option */
}
@@ -742,7 +729,6 @@ static void dhcp_global_add(const char *var)
static int dhcp_global_init(void)
{
struct dhcp_opt *opt;
- struct dhcp_param *param;
int i;
for (i = 0; i < ARRAY_SIZE(dhcp_options); i++) {
@@ -754,15 +740,6 @@ static int dhcp_global_init(void)
dhcp_global_add(opt->barebox_dhcp_global);
}
- for (i = 0; i < ARRAY_SIZE(dhcp_params); i++) {
- param = &dhcp_params[i];
-
- if (!param->barebox_dhcp_global)
- continue;
-
- dhcp_global_add(param->barebox_dhcp_global);
- }
-
return 0;
}
late_initcall(dhcp_global_init);
diff --git a/net/dns.c b/net/dns.c
index 0e16ea2c9d..5488e9f7b8 100644
--- a/net/dns.c
+++ b/net/dns.c
@@ -59,7 +59,7 @@ static uint64_t dns_timer_start;
static int dns_state;
static IPaddr_t dns_ip;
-static int dns_send(char *name)
+static int dns_send(const char *name)
{
int ret;
struct header *header;
@@ -199,7 +199,7 @@ static void dns_handler(void *ctx, char *packet, unsigned len)
net_eth_to_udplen(packet));
}
-IPaddr_t resolv(char *host)
+IPaddr_t resolv(const char *host)
{
IPaddr_t ip;
const char *ns;