From 633cd47285a206335731fd8b5fdce708574a3952 Mon Sep 17 00:00:00 2001 From: Dan Williams Date: Thu, 10 Feb 2005 20:54:04 +0000 Subject: [PATCH] 2005-02-10 Dan Williams * dhcpcd/buildmsg.c - (fill_host_and_class_id): only fill in client and class IDs if they are set by callers. * dhcpcd/client.c - (class_id_setup): don't autogenerate a class ID, only use one we're given, if any. - (client_id_setup): don't autogenerate a client ID, only use one we're given, if any. * dhcpcd/dhcpcd.c - (dhcp_interface_init): ensure that client options are correctly NULL terminated * src/NetworkManagerDHCP.c - (nm_device_dhcp_request): pass hostname to dhcp library git-svn-id: http://svn-archive.gnome.org/svn/NetworkManager/trunk@429 4912f4e0-d625-0410-9fb7-b9a5a253dbdc --- ChangeLog | 19 +++++++++++++++++++ dhcpcd/buildmsg.c | 25 ++++++++++++++++--------- dhcpcd/client.c | 16 ++-------------- dhcpcd/dhcpcd.c | 5 +++++ src/NetworkManagerDHCP.c | 3 ++- 5 files changed, 44 insertions(+), 24 deletions(-) diff --git a/ChangeLog b/ChangeLog index bf74d8d9bb..f7768f7dac 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,22 @@ +2005-02-10 Dan Williams + + * dhcpcd/buildmsg.c + - (fill_host_and_class_id): only fill in client and class IDs if + they are set by callers. + + * dhcpcd/client.c + - (class_id_setup): don't autogenerate a class ID, only use one + we're given, if any. + - (client_id_setup): don't autogenerate a client ID, only use one + we're given, if any. + + * dhcpcd/dhcpcd.c + - (dhcp_interface_init): ensure that client options are correctly + NULL terminated + + * src/NetworkManagerDHCP.c + - (nm_device_dhcp_request): pass hostname to dhcp library + 2005-02-10 Dan Williams * dhcpcd/client.c diff --git a/dhcpcd/buildmsg.c b/dhcpcd/buildmsg.c index b343d0bfd9..79b8ec7559 100644 --- a/dhcpcd/buildmsg.c +++ b/dhcpcd/buildmsg.c @@ -61,22 +61,29 @@ unsigned char *fill_host_and_class_id (dhcp_interface *iface, unsigned char *p) const char *host_name = iface->client_options->host_name; int host_name_len = strlen (host_name); - if ( host_name_len ) + if (host_name_len) { *p++ = hostName; *p++ = host_name_len; memcpy (p, host_name, host_name_len); p += host_name_len; } - *p++ = dhcpClassIdentifier; - *p++ = iface->cls_id_len; - memcpy (p, iface->cls_id, iface->cls_id_len); - p += iface->cls_id_len; - *p++ = dhcpClientIdentifier; - *p++ = iface->cli_id_len; - memcpy (p, iface->cli_id, iface->cli_id_len); - p += iface->cli_id_len; + if (iface->cls_id_len) + { + *p++ = dhcpClassIdentifier; + *p++ = iface->cls_id_len; + memcpy (p, iface->cls_id, iface->cls_id_len); + p += iface->cls_id_len; + } + + if (iface->cli_id_len) + { + *p++ = dhcpClientIdentifier; + *p++ = iface->cli_id_len; + memcpy (p, iface->cli_id, iface->cli_id_len); + p += iface->cli_id_len; + } return p; } diff --git a/dhcpcd/client.c b/dhcpcd/client.c index 98d28a43cf..e469c7a639 100644 --- a/dhcpcd/client.c +++ b/dhcpcd/client.c @@ -286,6 +286,7 @@ void class_id_setup (dhcp_interface *iface, const char *g_cls_id) if (!iface) return; + iface->cls_id_len = 0; memset (iface->cls_id, 0, DHCP_CLASS_ID_MAX_LEN); if (g_cls_id) @@ -296,14 +297,6 @@ void class_id_setup (dhcp_interface *iface, const char *g_cls_id) memcpy (iface->cls_id, g_cls_id, g_cls_id_len); iface->cls_id_len = g_cls_id_len; } - else - { - struct utsname sname; - if ( uname(&sname) ) - syslog (LOG_ERR,"class_id_setup(): uname returned an error: %m\n"); - snprintf (iface->cls_id, DHCP_CLASS_ID_MAX_LEN, "%s", sname.sysname); - iface->cls_id_len = strlen (iface->cls_id); - } } /*****************************************************************************/ void client_id_setup (dhcp_interface *iface, const char *g_cli_id) @@ -313,6 +306,7 @@ void client_id_setup (dhcp_interface *iface, const char *g_cli_id) if (!iface) return; + iface->cli_id_len = 0; memset (iface->cli_id, 0, DHCP_CLIENT_ID_MAX_LEN); c = iface->cli_id; @@ -325,12 +319,6 @@ void client_id_setup (dhcp_interface *iface, const char *g_cli_id) memcpy (c, g_cli_id, g_cli_id_len); iface->cli_id_len = g_cli_id_len + 1; } - else - { - *c++ = ARPHRD_ETHER; /* type: Ethernet address */ - memcpy (c, iface->chaddr, ETH_ALEN); - iface->cli_id_len = ETH_ALEN + 1; - } } /*****************************************************************************/ void release_dhcp_options (dhcp_interface *iface) diff --git a/dhcpcd/dhcpcd.c b/dhcpcd/dhcpcd.c index ec47718bb4..4cd55860fb 100644 --- a/dhcpcd/dhcpcd.c +++ b/dhcpcd/dhcpcd.c @@ -72,11 +72,16 @@ dhcp_interface *dhcp_interface_init (const char *if_name, dhcp_client_options *i iface->sk = -1; iface->foo_sk = -1; + /* Copy in client-specific options */ if (!(opts = calloc (1, sizeof (dhcp_client_options)))) goto err_out; memcpy (opts, in_opts, sizeof (dhcp_client_options)); + opts->host_name[DHCP_HOSTNAME_MAX_LEN - 1] = '\0'; + opts->class_id[DHCP_CLASS_ID_MAX_LEN - 1] = '\0'; + opts->client_id[DHCP_CLIENT_ID_MAX_LEN - 1] = '\0'; iface->client_options = opts; + /* Grab a control socket for the device */ memset (&ifr, 0, sizeof(struct ifreq)); memcpy (ifr.ifr_name, iface->iface, strlen (iface->iface)); iface->sk = socket (AF_PACKET, SOCK_PACKET, htons(ETH_P_ALL)); diff --git a/src/NetworkManagerDHCP.c b/src/NetworkManagerDHCP.c index 4a9d499b57..2323926a01 100644 --- a/src/NetworkManagerDHCP.c +++ b/src/NetworkManagerDHCP.c @@ -208,7 +208,8 @@ int nm_device_dhcp_request (NMDevice *dev) } memset (&opts, 0, sizeof (dhcp_client_options)); - opts.base_timeout = 30; + gethostname (&(opts.host_name[0]), DHCP_HOSTNAME_MAX_LEN); + opts.base_timeout = 30; if (!(dev->dhcp_iface = dhcp_interface_init (nm_device_get_iface (dev), &opts))) return RET_DHCP_ERROR;