add support for setting the dhcp vendor class option (option 60).
udhcpc now has a -V (--vendorclass), which will replace the default "udhcpRELEASE" string in this option.
This commit is contained in:
parent
2f9c30a2d5
commit
28de951b02
@ -2998,10 +2998,11 @@
|
|||||||
"Adjust filesystem options on ext[23] filesystems.\n\n"
|
"Adjust filesystem options on ext[23] filesystems.\n\n"
|
||||||
|
|
||||||
#define udhcpc_trivial_usage \
|
#define udhcpc_trivial_usage \
|
||||||
"[-Cfbnqv] [-c CLIENTID] [-H HOSTNAME] [-i INTERFACE]\n[-p pidfile] [-r IP] [-s script]"
|
"[-Cfbnqv] [-c CID] [-V VCLS] [-H HOSTNAME] [-i INTERFACE]\n[-p pidfile] [-r IP] [-s script]"
|
||||||
#define udhcpc_full_usage \
|
#define udhcpc_full_usage \
|
||||||
"\t-c,\t--clientid=CLIENTID\tSet client identifier\n" \
|
"\t-c,\t--clientid=CLIENTID\tSet client identifier\n" \
|
||||||
"\t-C,\t--clientid-none\tSuppress default client identifier\n" \
|
"\t-C,\t--clientid-none\tSuppress default client identifier\n" \
|
||||||
|
"\t-V,\t--vendorclass=CLASSID\tSet vendor class identifier\n" \
|
||||||
"\t-H,\t--hostname=HOSTNAME\tClient hostname\n" \
|
"\t-H,\t--hostname=HOSTNAME\tClient hostname\n" \
|
||||||
"\t-h,\t \tAlias for -H\n" \
|
"\t-h,\t \tAlias for -H\n" \
|
||||||
"\t-f,\t--foreground\tDo not fork after getting lease\n" \
|
"\t-f,\t--foreground\tDo not fork after getting lease\n" \
|
||||||
|
@ -10,7 +10,9 @@ command line options
|
|||||||
|
|
||||||
The command line options for the udhcp client are:
|
The command line options for the udhcp client are:
|
||||||
|
|
||||||
-c, --clientid=CLIENTID Client identifier
|
-c, --clientid=CLIENTID Set client identifier. Type is first char.
|
||||||
|
-C, --clientid-none Suppress default client identifier
|
||||||
|
-V, --vendorclass=CLASSID Set vendor class identifier
|
||||||
-H, --hostname=HOSTNAME Client hostname
|
-H, --hostname=HOSTNAME Client hostname
|
||||||
-h, Alias for -H
|
-h, Alias for -H
|
||||||
-F, --fqdn=FQDN Client fully qualified domain name
|
-F, --fqdn=FQDN Client fully qualified domain name
|
||||||
|
@ -69,18 +69,13 @@ unsigned long random_xid(void)
|
|||||||
/* initialize a packet with the proper defaults */
|
/* initialize a packet with the proper defaults */
|
||||||
static void init_packet(struct dhcpMessage *packet, char type)
|
static void init_packet(struct dhcpMessage *packet, char type)
|
||||||
{
|
{
|
||||||
struct vendor {
|
|
||||||
char vendor, length;
|
|
||||||
char str[sizeof("udhcp "VERSION)];
|
|
||||||
} vendor_id = { DHCP_VENDOR, sizeof("udhcp "VERSION) - 1, "udhcp "VERSION};
|
|
||||||
|
|
||||||
init_header(packet, type);
|
init_header(packet, type);
|
||||||
memcpy(packet->chaddr, client_config.arp, 6);
|
memcpy(packet->chaddr, client_config.arp, 6);
|
||||||
if (client_config.clientid)
|
if (client_config.clientid)
|
||||||
add_option_string(packet->options, client_config.clientid);
|
add_option_string(packet->options, client_config.clientid);
|
||||||
if (client_config.hostname) add_option_string(packet->options, client_config.hostname);
|
if (client_config.hostname) add_option_string(packet->options, client_config.hostname);
|
||||||
if (client_config.fqdn) add_option_string(packet->options, client_config.fqdn);
|
if (client_config.fqdn) add_option_string(packet->options, client_config.fqdn);
|
||||||
add_option_string(packet->options, (uint8_t *) &vendor_id);
|
add_option_string(packet->options, client_config.vendorclass);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -66,6 +66,7 @@ struct client_config_t client_config = {
|
|||||||
.pidfile = NULL,
|
.pidfile = NULL,
|
||||||
.script = DEFAULT_SCRIPT,
|
.script = DEFAULT_SCRIPT,
|
||||||
.clientid = NULL,
|
.clientid = NULL,
|
||||||
|
.vendorclass = NULL,
|
||||||
.hostname = NULL,
|
.hostname = NULL,
|
||||||
.fqdn = NULL,
|
.fqdn = NULL,
|
||||||
.ifindex = 0,
|
.ifindex = 0,
|
||||||
@ -77,8 +78,9 @@ static void __attribute__ ((noreturn)) show_usage(void)
|
|||||||
{
|
{
|
||||||
printf(
|
printf(
|
||||||
"Usage: udhcpc [OPTIONS]\n\n"
|
"Usage: udhcpc [OPTIONS]\n\n"
|
||||||
" -c, --clientid=CLIENTID Set client identifier\n"
|
" -c, --clientid=CLIENTID Set client identifier - type is first char\n"
|
||||||
" -C, --clientid-none Suppress default client identifier\n"
|
" -C, --clientid-none Suppress default client identifier\n"
|
||||||
|
" -V, --vendorclass=CLASSID Set vendor class identifier\n"
|
||||||
" -H, --hostname=HOSTNAME Client hostname\n"
|
" -H, --hostname=HOSTNAME Client hostname\n"
|
||||||
" -h Alias for -H\n"
|
" -h Alias for -H\n"
|
||||||
" -F, --fqdn=FQDN Client fully qualified domain name\n"
|
" -F, --fqdn=FQDN Client fully qualified domain name\n"
|
||||||
@ -199,6 +201,7 @@ int main(int argc, char *argv[])
|
|||||||
static const struct option arg_options[] = {
|
static const struct option arg_options[] = {
|
||||||
{"clientid", required_argument, 0, 'c'},
|
{"clientid", required_argument, 0, 'c'},
|
||||||
{"clientid-none", no_argument, 0, 'C'},
|
{"clientid-none", no_argument, 0, 'C'},
|
||||||
|
{"vendorclass", required_argument, 0, 'V'},
|
||||||
{"foreground", no_argument, 0, 'f'},
|
{"foreground", no_argument, 0, 'f'},
|
||||||
{"background", no_argument, 0, 'b'},
|
{"background", no_argument, 0, 'b'},
|
||||||
{"hostname", required_argument, 0, 'H'},
|
{"hostname", required_argument, 0, 'H'},
|
||||||
@ -217,7 +220,7 @@ int main(int argc, char *argv[])
|
|||||||
/* get options */
|
/* get options */
|
||||||
while (1) {
|
while (1) {
|
||||||
int option_index = 0;
|
int option_index = 0;
|
||||||
c = getopt_long(argc, argv, "c:CfbH:h:F:i:np:qr:s:v", arg_options, &option_index);
|
c = getopt_long(argc, argv, "c:CV:fbH:h:F:i:np:qr:s:v", arg_options, &option_index);
|
||||||
if (c == -1) break;
|
if (c == -1) break;
|
||||||
|
|
||||||
switch (c) {
|
switch (c) {
|
||||||
@ -235,6 +238,14 @@ int main(int argc, char *argv[])
|
|||||||
if (client_config.clientid) show_usage();
|
if (client_config.clientid) show_usage();
|
||||||
no_clientid = 1;
|
no_clientid = 1;
|
||||||
break;
|
break;
|
||||||
|
case 'V':
|
||||||
|
len = strlen(optarg) > 255 ? 255 : strlen(optarg);
|
||||||
|
if (client_config.vendorclass) free(client_config.vendorclass);
|
||||||
|
client_config.vendorclass = xmalloc(len + 2);
|
||||||
|
client_config.vendorclass[OPT_CODE] = DHCP_VENDOR;
|
||||||
|
client_config.vendorclass[OPT_LEN] = len;
|
||||||
|
strncpy(client_config.vendorclass + OPT_DATA, optarg, len);
|
||||||
|
break;
|
||||||
case 'f':
|
case 'f':
|
||||||
client_config.foreground = 1;
|
client_config.foreground = 1;
|
||||||
break;
|
break;
|
||||||
@ -310,6 +321,16 @@ int main(int argc, char *argv[])
|
|||||||
memcpy(client_config.clientid + 3, client_config.arp, 6);
|
memcpy(client_config.clientid + 3, client_config.arp, 6);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!client_config.vendorclass) {
|
||||||
|
client_config.vendorclass = xmalloc(sizeof("udhcp "VERSION) + 2);
|
||||||
|
client_config.vendorclass[OPT_CODE] = DHCP_VENDOR;
|
||||||
|
client_config.vendorclass[OPT_LEN] = sizeof("udhcp "VERSION) - 1;
|
||||||
|
client_config.vendorclass[OPT_DATA] = 1;
|
||||||
|
memcpy(&client_config.vendorclass[OPT_DATA],
|
||||||
|
"udhcp "VERSION, sizeof("udhcp "VERSION) - 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/* setup the signal pipe */
|
/* setup the signal pipe */
|
||||||
udhcp_sp_setup();
|
udhcp_sp_setup();
|
||||||
|
|
||||||
|
@ -26,6 +26,7 @@ struct client_config_t {
|
|||||||
char *pidfile; /* Optionally store the process ID */
|
char *pidfile; /* Optionally store the process ID */
|
||||||
char *script; /* User script to run at dhcp events */
|
char *script; /* User script to run at dhcp events */
|
||||||
uint8_t *clientid; /* Optional client id to use */
|
uint8_t *clientid; /* Optional client id to use */
|
||||||
|
uint8_t *vendorclass; /* Optional vendor class-id to use */
|
||||||
uint8_t *hostname; /* Optional hostname to use */
|
uint8_t *hostname; /* Optional hostname to use */
|
||||||
uint8_t *fqdn; /* Optional fully qualified domain name to use */
|
uint8_t *fqdn; /* Optional fully qualified domain name to use */
|
||||||
int ifindex; /* Index number of the interface to use */
|
int ifindex; /* Index number of the interface to use */
|
||||||
|
Loading…
x
Reference in New Issue
Block a user