Extract subroutine do_setifcaps() and fix the bug that uwe@ reported
in capabilities-setting. Use prop_dictionary_util(3). Rename the parser snpaoffset to parse_snpaoffset.
This commit is contained in:
parent
502f5a16a5
commit
1c6c1fd531
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: af_iso.c,v 1.8 2008/05/06 16:15:17 dyoung Exp $ */
|
||||
/* $NetBSD: af_iso.c,v 1.9 2008/05/06 21:20:05 dyoung Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1983, 1993
|
||||
@ -33,7 +33,7 @@
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
#ifndef lint
|
||||
__RCSID("$NetBSD: af_iso.c,v 1.8 2008/05/06 16:15:17 dyoung Exp $");
|
||||
__RCSID("$NetBSD: af_iso.c,v 1.9 2008/05/06 21:20:05 dyoung Exp $");
|
||||
#endif /* not lint */
|
||||
|
||||
#include <sys/param.h>
|
||||
@ -74,8 +74,9 @@ struct sockaddr_iso *sisotab[] = {
|
||||
|
||||
static void adjust_nsellength(uint8_t);
|
||||
|
||||
struct pinteger snpaoffset = PINTEGER_INITIALIZER1(&snpaoffset, "snpaoffset",
|
||||
INT_MIN, INT_MAX, 10, setsnpaoffset, "snpaoffset", &command_root.pb_parser);
|
||||
struct pinteger parse_snpaoffset = PINTEGER_INITIALIZER1(&snpaoffset,
|
||||
"snpaoffset", INT_MIN, INT_MAX, 10, setsnpaoffset, "snpaoffset",
|
||||
&command_root.pb_parser);
|
||||
struct pinteger parse_nsellength = PINTEGER_INITIALIZER1(&nsellength,
|
||||
"nsellength", 0, UINT8_MAX, 10, setnsellength, "nsellength",
|
||||
&command_root.pb_parser);
|
||||
@ -97,14 +98,13 @@ iso_getaddr(const struct paddr_prefix *pfx, int which)
|
||||
int
|
||||
setsnpaoffset(prop_dictionary_t env, prop_dictionary_t xenv)
|
||||
{
|
||||
prop_number_t num;
|
||||
int64_t snpaoffset;
|
||||
|
||||
num = (prop_number_t)prop_dictionary_get(env, "snpaoffset");
|
||||
if (num == NULL) {
|
||||
if (!prop_dictionary_get_int64(env, "snpaoffset", &snpaoffset)) {
|
||||
errno = ENOENT;
|
||||
return -1;
|
||||
}
|
||||
iso_addreq.ifra_snpaoffset = (int)prop_number_integer_value(num);
|
||||
iso_addreq.ifra_snpaoffset = snpaoffset;
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -112,17 +112,16 @@ int
|
||||
setnsellength(prop_dictionary_t env, prop_dictionary_t xenv)
|
||||
{
|
||||
int af;
|
||||
prop_number_t num;
|
||||
uint8_t nsellength;
|
||||
|
||||
if ((af = getaf(env)) == -1 || af != AF_ISO)
|
||||
errx(EXIT_FAILURE, "Setting NSEL length valid only for iso");
|
||||
|
||||
num = (prop_number_t)prop_dictionary_get(env, "nsellength");
|
||||
if (num == NULL) {
|
||||
if (!prop_dictionary_get_uint8(env, "nsellength", &nsellength)) {
|
||||
errno = ENOENT;
|
||||
return -1;
|
||||
}
|
||||
adjust_nsellength((uint8_t)prop_number_integer_value(num));
|
||||
adjust_nsellength(nsellength);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: af_iso.h,v 1.4 2008/05/06 16:15:17 dyoung Exp $ */
|
||||
/* $NetBSD: af_iso.h,v 1.5 2008/05/06 21:20:05 dyoung Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1983, 1993
|
||||
@ -37,7 +37,7 @@
|
||||
/* XXX */
|
||||
extern struct iso_ifreq iso_ridreq;
|
||||
extern struct iso_aliasreq iso_addreq;
|
||||
extern struct pinteger parse_nsellength, snpaoffset;
|
||||
extern struct pinteger parse_nsellength, parse_snpaoffset;
|
||||
|
||||
int setsnpaoffset(prop_dictionary_t, prop_dictionary_t);
|
||||
int setnsellength(prop_dictionary_t, prop_dictionary_t);
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: ifconfig.c,v 1.191 2008/05/06 18:16:34 dyoung Exp $ */
|
||||
/* $NetBSD: ifconfig.c,v 1.192 2008/05/06 21:20:05 dyoung Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 1997, 1998, 2000 The NetBSD Foundation, Inc.
|
||||
@ -69,7 +69,7 @@ __COPYRIGHT("@(#) Copyright (c) 1983, 1993\n\
|
||||
#if 0
|
||||
static char sccsid[] = "@(#)ifconfig.c 8.2 (Berkeley) 2/16/94";
|
||||
#else
|
||||
__RCSID("$NetBSD: ifconfig.c,v 1.191 2008/05/06 18:16:34 dyoung Exp $");
|
||||
__RCSID("$NetBSD: ifconfig.c,v 1.192 2008/05/06 21:20:05 dyoung Exp $");
|
||||
#endif
|
||||
#endif /* not lint */
|
||||
|
||||
@ -354,7 +354,7 @@ struct kwinst misckw[] = {
|
||||
, {.k_word = "phase", .k_nextparser = &phase.pi_parser}
|
||||
, {.k_word = "range", .k_nextparser = &parse_range.ps_parser}
|
||||
, {.k_word = "nsellength", .k_nextparser = &parse_nsellength.pi_parser}
|
||||
, {.k_word = "snpaoffset", .k_nextparser = &snpaoffset.pi_parser}
|
||||
, {.k_word = "snpaoffset", .k_nextparser = &parse_snpaoffset.pi_parser}
|
||||
/* CARP */
|
||||
, {.k_word = "advbase", .k_nextparser = &parse_advbase.pi_parser}
|
||||
, {.k_word = "advskew", .k_nextparser = &parse_advskew.pi_parser}
|
||||
@ -565,6 +565,22 @@ media_status_exec(prop_dictionary_t env, prop_dictionary_t xenv)
|
||||
exit(carrier(env));
|
||||
}
|
||||
|
||||
static void
|
||||
do_setifcaps(int s, const char *ifname, prop_dictionary_t env)
|
||||
{
|
||||
struct ifcapreq ifcr;
|
||||
prop_data_t d;
|
||||
|
||||
d = (prop_data_t )prop_dictionary_get(env, "ifcap");
|
||||
if (d == NULL || sizeof(ifcr) != prop_data_size(d))
|
||||
return;
|
||||
|
||||
memcpy(&ifcr, prop_data_data_nocopy(d), sizeof(ifcr));
|
||||
estrlcpy(ifcr.ifcr_name, ifname, sizeof(ifcr.ifcr_name));
|
||||
if (ioctl(s, SIOCSIFCAP, &ifcr) == -1)
|
||||
err(EXIT_FAILURE, "SIOCSIFCAP");
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, char **argv)
|
||||
{
|
||||
@ -576,7 +592,6 @@ main(int argc, char **argv)
|
||||
int ch, narg = 0, rc;
|
||||
prop_dictionary_t env, xenv;
|
||||
const char *ifname;
|
||||
struct ifcapreq ifcr;
|
||||
|
||||
memset(match, 0, sizeof(match));
|
||||
|
||||
@ -762,12 +777,7 @@ main(int argc, char **argv)
|
||||
}
|
||||
|
||||
do_setifpreference(env);
|
||||
if (prop_dictionary_get(env, "ifcap") != NULL) {
|
||||
memset(&ifcr, 0, sizeof(ifcr));
|
||||
estrlcpy(ifcr.ifcr_name, ifname, sizeof(ifcr.ifcr_name));
|
||||
if (ioctl(s, SIOCSIFCAP, &ifcr) == -1)
|
||||
err(EXIT_FAILURE, "SIOCSIFCAP");
|
||||
}
|
||||
do_setifcaps(s, ifname, env);
|
||||
|
||||
if (check_up_state == 1)
|
||||
check_ifflags_up(ifname);
|
||||
|
Loading…
Reference in New Issue
Block a user