Fri Dec 21 08:58:08 2018 UTC ()
 Add SIOCSETHERCAP. It's used to change ec_capenable.


(msaitoh)
diff -r1.2 -r1.3 src/sbin/ifconfig/ether.c
diff -r1.14 -r1.15 src/sbin/ifconfig/extern.h
diff -r1.237 -r1.238 src/sbin/ifconfig/ifconfig.c
diff -r1.442 -r1.443 src/sys/net/if.c
diff -r1.271 -r1.272 src/sys/net/if_ethersubr.c
diff -r1.35 -r1.36 src/sys/sys/sockio.h

cvs diff -r1.2 -r1.3 src/sbin/ifconfig/ether.c (expand / switch to unified diff)

--- src/sbin/ifconfig/ether.c 2012/11/01 13:43:23 1.2
+++ src/sbin/ifconfig/ether.c 2018/12/21 08:58:08 1.3
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: ether.c,v 1.2 2012/11/01 13:43:23 pgoyette Exp $ */ 1/* $NetBSD: ether.c,v 1.3 2018/12/21 08:58:08 msaitoh Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 1983, 1993 4 * Copyright (c) 1983, 1993
5 * The Regents of the University of California. All rights reserved. 5 * The Regents of the University of California. All rights reserved.
6 * 6 *
7 * Redistribution and use in source and binary forms, with or without 7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions 8 * modification, are permitted provided that the following conditions
9 * are met: 9 * are met:
10 * 1. Redistributions of source code must retain the above copyright 10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer. 11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright 12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the 13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution. 14 * documentation and/or other materials provided with the distribution.
@@ -21,55 +21,144 @@ @@ -21,55 +21,144 @@
21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 22 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
23 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 23 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 * SUCH DAMAGE. 29 * SUCH DAMAGE.
30 */ 30 */
31 31
32#include <sys/cdefs.h> 32#include <sys/cdefs.h>
33#ifndef lint 33#ifndef lint
34__RCSID("$NetBSD: ether.c,v 1.2 2012/11/01 13:43:23 pgoyette Exp $"); 34__RCSID("$NetBSD: ether.c,v 1.3 2018/12/21 08:58:08 msaitoh Exp $");
35#endif /* not lint */ 35#endif /* not lint */
36 36
37#include <sys/param.h>  37#include <sys/param.h>
38#include <sys/ioctl.h>  38#include <sys/ioctl.h>
39 39
40#include <net/if.h>  40#include <net/if.h>
41#include <net/if_ether.h> 41#include <net/if_ether.h>
42 42
 43#include <assert.h>
43#include <ctype.h> 44#include <ctype.h>
44#include <err.h> 45#include <err.h>
45#include <errno.h> 46#include <errno.h>
46#include <string.h> 47#include <string.h>
47#include <stdlib.h> 48#include <stdlib.h>
48#include <stdio.h> 49#include <stdio.h>
49#include <util.h> 50#include <util.h>
50 51
51#include "env.h" 52#include "env.h"
52#include "parse.h" 53#include "parse.h"
53#include "extern.h" 54#include "extern.h"
54#include "prog_ops.h" 55#include "prog_ops.h"
55 56
56static void ether_status(prop_dictionary_t, prop_dictionary_t); 57static void ether_status(prop_dictionary_t, prop_dictionary_t);
57static void ether_constructor(void) __attribute__((constructor)); 58static void ether_constructor(void) __attribute__((constructor));
 59static int setethercaps(prop_dictionary_t, prop_dictionary_t);
58 60
59static status_func_t status; 61static status_func_t status;
 62static cmdloop_branch_t branch;
60 63
61#define MAX_PRINT_LEN 55 64#define MAX_PRINT_LEN 55
62 65
 66static const struct kwinst ethercapskw[] = {
 67#if 0 /* notyet */
 68 IFKW("vlan-hwfilter", ETHERCAP_VLAN_HWFILTER)
 69#endif
 70 IFKW("eee", ETHERCAP_EEE)
 71};
 72
 73struct pkw ethercaps = PKW_INITIALIZER(&ethercaps, "ethercaps", setethercaps,
 74 "ethercap", ethercapskw, __arraycount(ethercapskw),
 75 &command_root.pb_parser);
 76
 77void
 78do_setethercaps(prop_dictionary_t env)
 79{
 80 struct eccapreq eccr;
 81 prop_data_t d;
 82
 83 d = (prop_data_t )prop_dictionary_get(env, "ethercaps");
 84 if (d == NULL)
 85 return;
 86
 87 assert(sizeof(eccr) == prop_data_size(d));
 88
 89 memcpy(&eccr, prop_data_data_nocopy(d), sizeof(eccr));
 90 if (direct_ioctl(env, SIOCSETHERCAP, &eccr) == -1)
 91 err(EXIT_FAILURE, "SIOCSETHERCAP");
 92}
 93
 94static int
 95getethercaps(prop_dictionary_t env, prop_dictionary_t oenv,
 96 struct eccapreq *oeccr)
 97{
 98 bool rc;
 99 struct eccapreq eccr;
 100 const struct eccapreq *tmpeccr;
 101 prop_data_t capdata;
 102
 103 capdata = (prop_data_t)prop_dictionary_get(env, "ethercaps");
 104
 105 if (capdata != NULL) {
 106 tmpeccr = prop_data_data_nocopy(capdata);
 107 *oeccr = *tmpeccr;
 108 return 0;
 109 }
 110
 111 (void)direct_ioctl(env, SIOCGETHERCAP, &eccr);
 112 *oeccr = eccr;
 113
 114 capdata = prop_data_create_data(&eccr, sizeof(eccr));
 115
 116 rc = prop_dictionary_set(oenv, "ethercaps", capdata);
 117
 118 prop_object_release((prop_object_t)capdata);
 119
 120 return rc ? 0 : -1;
 121}
 122
 123static int
 124setethercaps(prop_dictionary_t env, prop_dictionary_t oenv)
 125{
 126 int64_t ethercap;
 127 bool rc;
 128 prop_data_t capdata;
 129 struct eccapreq eccr;
 130
 131 rc = prop_dictionary_get_int64(env, "ethercap", &ethercap);
 132 assert(rc);
 133
 134 if (getethercaps(env, oenv, &eccr) == -1)
 135 return -1;
 136
 137 if (ethercap < 0) {
 138 ethercap = -ethercap;
 139 eccr.eccr_capenable &= ~ethercap;
 140 } else
 141 eccr.eccr_capenable |= ethercap;
 142
 143 if ((capdata = prop_data_create_data(&eccr, sizeof(eccr))) == NULL)
 144 return -1;
 145
 146 rc = prop_dictionary_set(oenv, "ethercaps", capdata);
 147 prop_object_release((prop_object_t)capdata);
 148
 149 return rc ? 0 : -1;
 150}
 151
63void 152void
64ether_status(prop_dictionary_t env, prop_dictionary_t oenv) 153ether_status(prop_dictionary_t env, prop_dictionary_t oenv)
65{ 154{
66 struct eccapreq eccr; 155 struct eccapreq eccr;
67 char fbuf[BUFSIZ]; 156 char fbuf[BUFSIZ];
68 char *bp; 157 char *bp;
69 158
70 memset(&eccr, 0, sizeof(eccr)); 159 memset(&eccr, 0, sizeof(eccr));
71 160
72 if (direct_ioctl(env, SIOCGETHERCAP, &eccr) == -1) 161 if (direct_ioctl(env, SIOCGETHERCAP, &eccr) == -1)
73 return; 162 return;
74 163
75 if (eccr.eccr_capabilities != 0) { 164 if (eccr.eccr_capabilities != 0) {
@@ -84,16 +173,18 @@ ether_status(prop_dictionary_t env, prop @@ -84,16 +173,18 @@ ether_status(prop_dictionary_t env, prop
84 eccr.eccr_capenable, MAX_PRINT_LEN); 173 eccr.eccr_capenable, MAX_PRINT_LEN);
85 bp = fbuf; 174 bp = fbuf;
86 while (*bp != '\0') { 175 while (*bp != '\0') {
87 printf("\tec_enabled=%s\n", &bp[2]); 176 printf("\tec_enabled=%s\n", &bp[2]);
88 bp += strlen(bp) + 1; 177 bp += strlen(bp) + 1;
89 } 178 }
90 } 179 }
91} 180}
92 181
93static void 182static void
94ether_constructor(void) 183ether_constructor(void)
95{ 184{
96 185
 186 cmdloop_branch_init(&branch, &ethercaps.pk_parser);
 187 register_cmdloop_branch(&branch);
97 status_func_init(&status, ether_status); 188 status_func_init(&status, ether_status);
98 register_status(&status); 189 register_status(&status);
99} 190}

cvs diff -r1.14 -r1.15 src/sbin/ifconfig/extern.h (expand / switch to unified diff)

--- src/sbin/ifconfig/extern.h 2009/08/07 18:53:37 1.14
+++ src/sbin/ifconfig/extern.h 2018/12/21 08:58:08 1.15
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: extern.h,v 1.14 2009/08/07 18:53:37 dyoung Exp $ */ 1/* $NetBSD: extern.h,v 1.15 2018/12/21 08:58:08 msaitoh Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 1983, 1993 4 * Copyright (c) 1983, 1993
5 * The Regents of the University of California. All rights reserved. 5 * The Regents of the University of California. All rights reserved.
6 * 6 *
7 * Redistribution and use in source and binary forms, with or without 7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions 8 * modification, are permitted provided that the following conditions
9 * are met: 9 * are met:
10 * 1. Redistributions of source code must retain the above copyright 10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer. 11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright 12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the 13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution. 14 * documentation and/or other materials provided with the distribution.
@@ -77,17 +77,18 @@ typedef struct usage_func usage_func_t; @@ -77,17 +77,18 @@ typedef struct usage_func usage_func_t;
77typedef struct cmdloop_branch cmdloop_branch_t; 77typedef struct cmdloop_branch cmdloop_branch_t;
78 78
79void cmdloop_branch_init(cmdloop_branch_t *, struct parser *); 79void cmdloop_branch_init(cmdloop_branch_t *, struct parser *);
80int register_family(struct afswtch *); 80int register_family(struct afswtch *);
81int register_cmdloop_branch(cmdloop_branch_t *); 81int register_cmdloop_branch(cmdloop_branch_t *);
82void statistics_func_init(statistics_func_t *, statistics_cb_t); 82void statistics_func_init(statistics_func_t *, statistics_cb_t);
83void status_func_init(status_func_t *, status_cb_t); 83void status_func_init(status_func_t *, status_cb_t);
84void usage_func_init(usage_func_t *, usage_cb_t); 84void usage_func_init(usage_func_t *, usage_cb_t);
85int register_statistics(statistics_func_t *); 85int register_statistics(statistics_func_t *);
86int register_status(status_func_t *); 86int register_status(status_func_t *);
87int register_usage(usage_func_t *); 87int register_usage(usage_func_t *);
88int register_flag(int); 88int register_flag(int);
89bool get_flag(int); 89bool get_flag(int);
 90void do_setethercaps(prop_dictionary_t);
90 91
91extern bool lflag, Nflag, vflag, zflag; 92extern bool lflag, Nflag, vflag, zflag;
92 93
93#endif /* _IFCONFIG_EXTERN_H */ 94#endif /* _IFCONFIG_EXTERN_H */

cvs diff -r1.237 -r1.238 src/sbin/ifconfig/ifconfig.c (expand / switch to unified diff)

--- src/sbin/ifconfig/ifconfig.c 2018/11/15 04:36:46 1.237
+++ src/sbin/ifconfig/ifconfig.c 2018/12/21 08:58:08 1.238
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: ifconfig.c,v 1.237 2018/11/15 04:36:46 ozaki-r Exp $ */ 1/* $NetBSD: ifconfig.c,v 1.238 2018/12/21 08:58:08 msaitoh Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c) 1997, 1998, 2000 The NetBSD Foundation, Inc. 4 * Copyright (c) 1997, 1998, 2000 The NetBSD Foundation, Inc.
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * This code is derived from software contributed to The NetBSD Foundation 7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility, 8 * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility,
9 * NASA Ames Research Center. 9 * NASA Ames Research Center.
10 * 10 *
11 * Redistribution and use in source and binary forms, with or without 11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions 12 * modification, are permitted provided that the following conditions
13 * are met: 13 * are met:
14 * 1. Redistributions of source code must retain the above copyright 14 * 1. Redistributions of source code must retain the above copyright
@@ -53,27 +53,27 @@ @@ -53,27 +53,27 @@
53 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 53 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
54 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 54 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
55 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 55 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
56 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 56 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
57 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 57 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
58 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 58 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
59 * SUCH DAMAGE. 59 * SUCH DAMAGE.
60 */ 60 */
61 61
62#include <sys/cdefs.h> 62#include <sys/cdefs.h>
63#ifndef lint 63#ifndef lint
64__COPYRIGHT("@(#) Copyright (c) 1983, 1993\ 64__COPYRIGHT("@(#) Copyright (c) 1983, 1993\
65 The Regents of the University of California. All rights reserved."); 65 The Regents of the University of California. All rights reserved.");
66__RCSID("$NetBSD: ifconfig.c,v 1.237 2018/11/15 04:36:46 ozaki-r Exp $"); 66__RCSID("$NetBSD: ifconfig.c,v 1.238 2018/12/21 08:58:08 msaitoh Exp $");
67#endif /* not lint */ 67#endif /* not lint */
68 68
69#include <sys/param.h> 69#include <sys/param.h>
70#include <sys/queue.h> 70#include <sys/queue.h>
71#include <sys/socket.h> 71#include <sys/socket.h>
72#include <sys/ioctl.h> 72#include <sys/ioctl.h>
73 73
74#include <net/if.h> 74#include <net/if.h>
75#include <net/if_dl.h> 75#include <net/if_dl.h>
76#include <net/if_media.h> 76#include <net/if_media.h>
77#include <net/if_ether.h> 77#include <net/if_ether.h>
78#include <netinet/in.h> /* XXX */ 78#include <netinet/in.h> /* XXX */
79#include <netinet/in_var.h> /* XXX */ 79#include <netinet/in_var.h> /* XXX */
@@ -789,26 +789,27 @@ main(int argc, char **argv) @@ -789,26 +789,27 @@ main(int argc, char **argv)
789 err(EXIT_FAILURE, "%s: getsock", __func__); 789 err(EXIT_FAILURE, "%s: getsock", __func__);
790 790
791 if ((ifname = getifname(env)) == NULL) 791 if ((ifname = getifname(env)) == NULL)
792 err(EXIT_FAILURE, "%s: getifname", __func__); 792 err(EXIT_FAILURE, "%s: getifname", __func__);
793 793
794 if ((afp = lookup_af_bynum(af)) == NULL) 794 if ((afp = lookup_af_bynum(af)) == NULL)
795 errx(EXIT_FAILURE, "%s: lookup_af_bynum", __func__); 795 errx(EXIT_FAILURE, "%s: lookup_af_bynum", __func__);
796 796
797 assert(afp->af_addr_commit != NULL); 797 assert(afp->af_addr_commit != NULL);
798 (*afp->af_addr_commit)(env, oenv); 798 (*afp->af_addr_commit)(env, oenv);
799 799
800 do_setifpreference(env); 800 do_setifpreference(env);
801 do_setifcaps(env); 801 do_setifcaps(env);
 802 do_setethercaps(env);
802 803
803 exit(EXIT_SUCCESS); 804 exit(EXIT_SUCCESS);
804} 805}
805 806
806static void 807static void
807init_afs(void) 808init_afs(void)
808{ 809{
809 size_t i; 810 size_t i;
810 const struct afswtch *afp; 811 const struct afswtch *afp;
811 struct kwinst kw = {.k_type = KW_T_INT}; 812 struct kwinst kw = {.k_type = KW_T_INT};
812 813
813 SIMPLEQ_FOREACH(afp, &aflist, af_next) { 814 SIMPLEQ_FOREACH(afp, &aflist, af_next) {
814 kw.k_word = afp->af_name; 815 kw.k_word = afp->af_name;

cvs diff -r1.442 -r1.443 src/sys/net/if.c (expand / switch to unified diff)

--- src/sys/net/if.c 2018/12/12 01:46:47 1.442
+++ src/sys/net/if.c 2018/12/21 08:58:08 1.443
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: if.c,v 1.442 2018/12/12 01:46:47 rin Exp $ */ 1/* $NetBSD: if.c,v 1.443 2018/12/21 08:58:08 msaitoh Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c) 1999, 2000, 2001, 2008 The NetBSD Foundation, Inc. 4 * Copyright (c) 1999, 2000, 2001, 2008 The NetBSD Foundation, Inc.
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * This code is derived from software contributed to The NetBSD Foundation 7 * This code is derived from software contributed to The NetBSD Foundation
8 * by William Studenmund and Jason R. Thorpe. 8 * by William Studenmund and Jason R. Thorpe.
9 * 9 *
10 * Redistribution and use in source and binary forms, with or without 10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions 11 * modification, are permitted provided that the following conditions
12 * are met: 12 * are met:
13 * 1. Redistributions of source code must retain the above copyright 13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer. 14 * notice, this list of conditions and the following disclaimer.
@@ -80,27 +80,27 @@ @@ -80,27 +80,27 @@
80 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 80 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
81 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 81 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
82 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 82 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
83 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 83 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
84 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 84 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
85 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 85 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
86 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 86 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
87 * SUCH DAMAGE. 87 * SUCH DAMAGE.
88 * 88 *
89 * @(#)if.c 8.5 (Berkeley) 1/9/95 89 * @(#)if.c 8.5 (Berkeley) 1/9/95
90 */ 90 */
91 91
92#include <sys/cdefs.h> 92#include <sys/cdefs.h>
93__KERNEL_RCSID(0, "$NetBSD: if.c,v 1.442 2018/12/12 01:46:47 rin Exp $"); 93__KERNEL_RCSID(0, "$NetBSD: if.c,v 1.443 2018/12/21 08:58:08 msaitoh Exp $");
94 94
95#if defined(_KERNEL_OPT) 95#if defined(_KERNEL_OPT)
96#include "opt_inet.h" 96#include "opt_inet.h"
97#include "opt_ipsec.h" 97#include "opt_ipsec.h"
98#include "opt_atalk.h" 98#include "opt_atalk.h"
99#include "opt_wlan.h" 99#include "opt_wlan.h"
100#include "opt_net_mpsafe.h" 100#include "opt_net_mpsafe.h"
101#include "opt_mrouting.h" 101#include "opt_mrouting.h"
102#endif 102#endif
103 103
104#include <sys/param.h> 104#include <sys/param.h>
105#include <sys/mbuf.h> 105#include <sys/mbuf.h>
106#include <sys/systm.h> 106#include <sys/systm.h>
@@ -3220,26 +3220,27 @@ doifioctl(struct socket *so, u_long cmd, @@ -3220,26 +3220,27 @@ doifioctl(struct socket *so, u_long cmd,
3220 case SIOCSIFFLAGS: 3220 case SIOCSIFFLAGS:
3221 case SIOCSIFCAP: 3221 case SIOCSIFCAP:
3222 case SIOCSIFMETRIC: 3222 case SIOCSIFMETRIC:
3223 case SIOCZIFDATA: 3223 case SIOCZIFDATA:
3224 case SIOCSIFMTU: 3224 case SIOCSIFMTU:
3225 case SIOCSIFPHYADDR: 3225 case SIOCSIFPHYADDR:
3226 case SIOCDIFPHYADDR: 3226 case SIOCDIFPHYADDR:
3227#ifdef INET6 3227#ifdef INET6
3228 case SIOCSIFPHYADDR_IN6: 3228 case SIOCSIFPHYADDR_IN6:
3229#endif 3229#endif
3230 case SIOCSLIFPHYADDR: 3230 case SIOCSLIFPHYADDR:
3231 case SIOCADDMULTI: 3231 case SIOCADDMULTI:
3232 case SIOCDELMULTI: 3232 case SIOCDELMULTI:
 3233 case SIOCSETHERCAP:
3233 case SIOCSIFMEDIA: 3234 case SIOCSIFMEDIA:
3234 case SIOCSDRVSPEC: 3235 case SIOCSDRVSPEC:
3235 case SIOCG80211: 3236 case SIOCG80211:
3236 case SIOCS80211: 3237 case SIOCS80211:
3237 case SIOCS80211NWID: 3238 case SIOCS80211NWID:
3238 case SIOCS80211NWKEY: 3239 case SIOCS80211NWKEY:
3239 case SIOCS80211POWER: 3240 case SIOCS80211POWER:
3240 case SIOCS80211BSSID: 3241 case SIOCS80211BSSID:
3241 case SIOCS80211CHANNEL: 3242 case SIOCS80211CHANNEL:
3242 case SIOCSLINKSTR: 3243 case SIOCSLINKSTR:
3243 if (l != NULL) { 3244 if (l != NULL) {
3244 error = kauth_authorize_network(l->l_cred, 3245 error = kauth_authorize_network(l->l_cred,
3245 KAUTH_NETWORK_INTERFACE, 3246 KAUTH_NETWORK_INTERFACE,

cvs diff -r1.271 -r1.272 src/sys/net/if_ethersubr.c (expand / switch to unified diff)

--- src/sys/net/if_ethersubr.c 2018/11/15 10:23:56 1.271
+++ src/sys/net/if_ethersubr.c 2018/12/21 08:58:08 1.272
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: if_ethersubr.c,v 1.271 2018/11/15 10:23:56 maxv Exp $ */ 1/* $NetBSD: if_ethersubr.c,v 1.272 2018/12/21 08:58:08 msaitoh Exp $ */
2 2
3/* 3/*
4 * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project. 4 * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * Redistribution and use in source and binary forms, with or without 7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions 8 * modification, are permitted provided that the following conditions
9 * are met: 9 * are met:
10 * 1. Redistributions of source code must retain the above copyright 10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer. 11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright 12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the 13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution. 14 * documentation and/or other materials provided with the distribution.
@@ -51,27 +51,27 @@ @@ -51,27 +51,27 @@
51 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 51 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
52 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 52 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
53 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 53 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
54 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 54 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
55 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 55 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
56 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 56 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
57 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 57 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
58 * SUCH DAMAGE. 58 * SUCH DAMAGE.
59 * 59 *
60 * @(#)if_ethersubr.c 8.2 (Berkeley) 4/4/96 60 * @(#)if_ethersubr.c 8.2 (Berkeley) 4/4/96
61 */ 61 */
62 62
63#include <sys/cdefs.h> 63#include <sys/cdefs.h>
64__KERNEL_RCSID(0, "$NetBSD: if_ethersubr.c,v 1.271 2018/11/15 10:23:56 maxv Exp $"); 64__KERNEL_RCSID(0, "$NetBSD: if_ethersubr.c,v 1.272 2018/12/21 08:58:08 msaitoh Exp $");
65 65
66#ifdef _KERNEL_OPT 66#ifdef _KERNEL_OPT
67#include "opt_inet.h" 67#include "opt_inet.h"
68#include "opt_atalk.h" 68#include "opt_atalk.h"
69#include "opt_mbuftrace.h" 69#include "opt_mbuftrace.h"
70#include "opt_mpls.h" 70#include "opt_mpls.h"
71#include "opt_gateway.h" 71#include "opt_gateway.h"
72#include "opt_pppoe.h" 72#include "opt_pppoe.h"
73#include "opt_net_mpsafe.h" 73#include "opt_net_mpsafe.h"
74#endif 74#endif
75 75
76#include "vlan.h" 76#include "vlan.h"
77#include "pppoe.h" 77#include "pppoe.h"
@@ -1362,34 +1362,76 @@ ether_delmulti(const struct sockaddr *sa @@ -1362,34 +1362,76 @@ ether_delmulti(const struct sockaddr *sa
1362 return ENETRESET; 1362 return ENETRESET;
1363 1363
1364error: 1364error:
1365 ETHER_UNLOCK(ec); 1365 ETHER_UNLOCK(ec);
1366 return error; 1366 return error;
1367} 1367}
1368 1368
1369void 1369void
1370ether_set_ifflags_cb(struct ethercom *ec, ether_cb_t cb) 1370ether_set_ifflags_cb(struct ethercom *ec, ether_cb_t cb)
1371{ 1371{
1372 ec->ec_ifflags_cb = cb; 1372 ec->ec_ifflags_cb = cb;
1373} 1373}
1374 1374
 1375static int
 1376ether_ioctl_reinit(struct ethercom *ec)
 1377{
 1378 struct ifnet *ifp = &ec->ec_if;
 1379 int error;
 1380
 1381 switch (ifp->if_flags & (IFF_UP | IFF_RUNNING)) {
 1382 case IFF_RUNNING:
 1383 /*
 1384 * If interface is marked down and it is running,
 1385 * then stop and disable it.
 1386 */
 1387 (*ifp->if_stop)(ifp, 1);
 1388 break;
 1389 case IFF_UP:
 1390 /*
 1391 * If interface is marked up and it is stopped, then
 1392 * start it.
 1393 */
 1394 return (*ifp->if_init)(ifp);
 1395 case IFF_UP | IFF_RUNNING:
 1396 error = 0;
 1397 if (ec->ec_ifflags_cb != NULL) {
 1398 error = (*ec->ec_ifflags_cb)(ec);
 1399 if (error == ENETRESET) {
 1400 /*
 1401 * Reset the interface to pick up
 1402 * changes in any other flags that
 1403 * affect the hardware state.
 1404 */
 1405 return (*ifp->if_init)(ifp);
 1406 }
 1407 } else
 1408 error = (*ifp->if_init)(ifp);
 1409 return error;
 1410 case 0:
 1411 break;
 1412 }
 1413
 1414 return 0;
 1415}
 1416
1375/* 1417/*
1376 * Common ioctls for Ethernet interfaces. Note, we must be 1418 * Common ioctls for Ethernet interfaces. Note, we must be
1377 * called at splnet(). 1419 * called at splnet().
1378 */ 1420 */
1379int 1421int
1380ether_ioctl(struct ifnet *ifp, u_long cmd, void *data) 1422ether_ioctl(struct ifnet *ifp, u_long cmd, void *data)
1381{ 1423{
1382 struct ethercom *ec = (void *) ifp; 1424 struct ethercom *ec = (void *)ifp;
1383 struct eccapreq *eccr; 1425 struct eccapreq *eccr;
1384 struct ifreq *ifr = (struct ifreq *)data; 1426 struct ifreq *ifr = (struct ifreq *)data;
1385 struct if_laddrreq *iflr = data; 1427 struct if_laddrreq *iflr = data;
1386 const struct sockaddr_dl *sdl; 1428 const struct sockaddr_dl *sdl;
1387 static const uint8_t zero[ETHER_ADDR_LEN]; 1429 static const uint8_t zero[ETHER_ADDR_LEN];
1388 int error; 1430 int error;
1389 1431
1390 switch (cmd) { 1432 switch (cmd) {
1391 case SIOCINITIFADDR: 1433 case SIOCINITIFADDR:
1392 { 1434 {
1393 struct ifaddr *ifa = (struct ifaddr *)data; 1435 struct ifaddr *ifa = (struct ifaddr *)data;
1394 if (ifa->ifa_addr->sa_family != AF_LINK 1436 if (ifa->ifa_addr->sa_family != AF_LINK
1395 && (ifp->if_flags & (IFF_UP | IFF_RUNNING)) != 1437 && (ifp->if_flags & (IFF_UP | IFF_RUNNING)) !=
@@ -1418,64 +1460,45 @@ ether_ioctl(struct ifnet *ifp, u_long cm @@ -1418,64 +1460,45 @@ ether_ioctl(struct ifnet *ifp, u_long cm
1418 return EINVAL; 1460 return EINVAL;
1419 else if ((error = ifioctl_common(ifp, cmd, data)) != ENETRESET) 1461 else if ((error = ifioctl_common(ifp, cmd, data)) != ENETRESET)
1420 return error; 1462 return error;
1421 else if (ifp->if_flags & IFF_UP) { 1463 else if (ifp->if_flags & IFF_UP) {
1422 /* Make sure the device notices the MTU change. */ 1464 /* Make sure the device notices the MTU change. */
1423 return (*ifp->if_init)(ifp); 1465 return (*ifp->if_init)(ifp);
1424 } else 1466 } else
1425 return 0; 1467 return 0;
1426 } 1468 }
1427 1469
1428 case SIOCSIFFLAGS: 1470 case SIOCSIFFLAGS:
1429 if ((error = ifioctl_common(ifp, cmd, data)) != 0) 1471 if ((error = ifioctl_common(ifp, cmd, data)) != 0)
1430 return error; 1472 return error;
1431 switch (ifp->if_flags & (IFF_UP | IFF_RUNNING)) { 1473 return ether_ioctl_reinit(ec);
1432 case IFF_RUNNING: 
1433 /* 
1434 * If interface is marked down and it is running, 
1435 * then stop and disable it. 
1436 */ 
1437 (*ifp->if_stop)(ifp, 1); 
1438 break; 
1439 case IFF_UP: 
1440 /* 
1441 * If interface is marked up and it is stopped, then 
1442 * start it. 
1443 */ 
1444 return (*ifp->if_init)(ifp); 
1445 case IFF_UP | IFF_RUNNING: 
1446 error = 0; 
1447 if (ec->ec_ifflags_cb != NULL) { 
1448 error = (*ec->ec_ifflags_cb)(ec); 
1449 if (error == ENETRESET) { 
1450 /* 
1451 * Reset the interface to pick up 
1452 * changes in any other flags that 
1453 * affect the hardware state. 
1454 */ 
1455 return (*ifp->if_init)(ifp); 
1456 } 
1457 } else 
1458 error = (*ifp->if_init)(ifp); 
1459 return error; 
1460 case 0: 
1461 break; 
1462 } 
1463 return 0; 
1464 case SIOCGETHERCAP: 1474 case SIOCGETHERCAP:
1465 eccr = (struct eccapreq *)data; 1475 eccr = (struct eccapreq *)data;
1466 eccr->eccr_capabilities = ec->ec_capabilities; 1476 eccr->eccr_capabilities = ec->ec_capabilities;
1467 eccr->eccr_capenable = ec->ec_capenable; 1477 eccr->eccr_capenable = ec->ec_capenable;
1468 return 0; 1478 return 0;
 1479 case SIOCSETHERCAP:
 1480 eccr = (struct eccapreq *)data;
 1481 if ((eccr->eccr_capenable & ~ec->ec_capabilities) != 0)
 1482 return EINVAL;
 1483 if (eccr->eccr_capenable == ec->ec_capenable)
 1484 return 0;
 1485#if 0 /* notyet */
 1486 ec->ec_capenable = (ec->ec_capenable & ETHERCAP_CANTCHANGE)
 1487 | (eccr->eccr_capenable & ~ETHERCAP_CANTCHANGE);
 1488#else
 1489 ec->ec_capenable = eccr->eccr_capenable;
 1490#endif
 1491 return ether_ioctl_reinit(ec);
1469 case SIOCADDMULTI: 1492 case SIOCADDMULTI:
1470 return ether_addmulti(ifreq_getaddr(cmd, ifr), ec); 1493 return ether_addmulti(ifreq_getaddr(cmd, ifr), ec);
1471 case SIOCDELMULTI: 1494 case SIOCDELMULTI:
1472 return ether_delmulti(ifreq_getaddr(cmd, ifr), ec); 1495 return ether_delmulti(ifreq_getaddr(cmd, ifr), ec);
1473 case SIOCSIFMEDIA: 1496 case SIOCSIFMEDIA:
1474 case SIOCGIFMEDIA: 1497 case SIOCGIFMEDIA:
1475 if (ec->ec_mii == NULL) 1498 if (ec->ec_mii == NULL)
1476 return ENOTTY; 1499 return ENOTTY;
1477 return ifmedia_ioctl(ifp, ifr, &ec->ec_mii->mii_media, cmd); 1500 return ifmedia_ioctl(ifp, ifr, &ec->ec_mii->mii_media, cmd);
1478 case SIOCALIFADDR: 1501 case SIOCALIFADDR:
1479 sdl = satocsdl(sstocsa(&iflr->addr)); 1502 sdl = satocsdl(sstocsa(&iflr->addr));
1480 if (sdl->sdl_family != AF_LINK) 1503 if (sdl->sdl_family != AF_LINK)
1481 ; 1504 ;

cvs diff -r1.35 -r1.36 src/sys/sys/sockio.h (expand / switch to unified diff)

--- src/sys/sys/sockio.h 2018/08/01 23:35:32 1.35
+++ src/sys/sys/sockio.h 2018/12/21 08:58:08 1.36
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: sockio.h,v 1.35 2018/08/01 23:35:32 rjs Exp $ */ 1/* $NetBSD: sockio.h,v 1.36 2018/12/21 08:58:08 msaitoh Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c) 1982, 1986, 1990, 1993, 1994 4 * Copyright (c) 1982, 1986, 1990, 1993, 1994
5 * The Regents of the University of California. All rights reserved. 5 * The Regents of the University of California. All rights reserved.
6 * 6 *
7 * Redistribution and use in source and binary forms, with or without 7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions 8 * modification, are permitted provided that the following conditions
9 * are met: 9 * are met:
10 * 1. Redistributions of source code must retain the above copyright 10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer. 11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright 12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the 13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution. 14 * documentation and/or other materials provided with the distribution.
@@ -131,22 +131,23 @@ @@ -131,22 +131,23 @@
131 131
132#define SIOCGIFDATA _IOWR('i', 133, struct ifdatareq) /* get if_data */ 132#define SIOCGIFDATA _IOWR('i', 133, struct ifdatareq) /* get if_data */
133#define SIOCZIFDATA _IOWR('i', 134, struct ifdatareq) /* get if_data then 133#define SIOCZIFDATA _IOWR('i', 134, struct ifdatareq) /* get if_data then
134 zero ctrs*/ 134 zero ctrs*/
135 135
136#define SIOCGLINKSTR _IOWR('i', 135, struct ifdrv) 136#define SIOCGLINKSTR _IOWR('i', 135, struct ifdrv)
137#define SIOCSLINKSTR _IOW('i', 136, struct ifdrv) 137#define SIOCSLINKSTR _IOW('i', 136, struct ifdrv)
138 138
139/* 137 is SIOCGATHSTATS in athioctl.h */ 139/* 137 is SIOCGATHSTATS in athioctl.h */
140/* 138 is SIOCGATHDIAG in athioctl.h */ 140/* 138 is SIOCGATHDIAG in athioctl.h */
141 141
142#define SIOCGETHERCAP _IOWR('i', 139, struct eccapreq) /* get ethercap */ 142#define SIOCGETHERCAP _IOWR('i', 139, struct eccapreq) /* get ethercap */
143#define SIOCGIFINDEX _IOWR('i', 140, struct ifreq) /* get ifnet index */ 143#define SIOCGIFINDEX _IOWR('i', 140, struct ifreq) /* get ifnet index */
 144#define SIOCSETHERCAP _IOW('i', 141, struct eccapreq) /* set ethercap */
144 145
145#define SIOCGUMBINFO _IOWR('i', 190, struct ifreq) /* get MBIM info */ 146#define SIOCGUMBINFO _IOWR('i', 190, struct ifreq) /* get MBIM info */
146#define SIOCSUMBPARAM _IOW('i', 191, struct ifreq) /* set MBIM param */ 147#define SIOCSUMBPARAM _IOW('i', 191, struct ifreq) /* set MBIM param */
147#define SIOCGUMBPARAM _IOWR('i', 192, struct ifreq) /* get MBIM param */ 148#define SIOCGUMBPARAM _IOWR('i', 192, struct ifreq) /* get MBIM param */
148 149
149#define SIOCSETPFSYNC _IOW('i', 247, struct ifreq)  150#define SIOCSETPFSYNC _IOW('i', 247, struct ifreq)
150#define SIOCGETPFSYNC _IOWR('i', 248, struct ifreq) 151#define SIOCGETPFSYNC _IOWR('i', 248, struct ifreq)
151 152
152#endif /* !_SYS_SOCKIO_H_ */ 153#endif /* !_SYS_SOCKIO_H_ */