ng_ether.c (121816) | ng_ether.c (123600) |
---|---|
1 2/* 3 * ng_ether.c 4 * 5 * Copyright (c) 1996-2000 Whistle Communications, Inc. 6 * All rights reserved. 7 * 8 * Subject to the following obligations and disclaimer of warranty, use and --- 23 unchanged lines hidden (view full) --- 32 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 33 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 34 * THIS SOFTWARE, EVEN IF WHISTLE COMMUNICATIONS IS ADVISED OF THE POSSIBILITY 35 * OF SUCH DAMAGE. 36 * 37 * Authors: Archie Cobbs <archie@freebsd.org> 38 * Julian Elischer <julian@freebsd.org> 39 * | 1 2/* 3 * ng_ether.c 4 * 5 * Copyright (c) 1996-2000 Whistle Communications, Inc. 6 * All rights reserved. 7 * 8 * Subject to the following obligations and disclaimer of warranty, use and --- 23 unchanged lines hidden (view full) --- 32 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 33 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 34 * THIS SOFTWARE, EVEN IF WHISTLE COMMUNICATIONS IS ADVISED OF THE POSSIBILITY 35 * OF SUCH DAMAGE. 36 * 37 * Authors: Archie Cobbs <archie@freebsd.org> 38 * Julian Elischer <julian@freebsd.org> 39 * |
40 * $FreeBSD: head/sys/netgraph/ng_ether.c 121816 2003-10-31 18:32:15Z brooks $ | 40 * $FreeBSD: head/sys/netgraph/ng_ether.c 123600 2003-12-17 12:40:34Z ru $ |
41 */ 42 43/* 44 * ng_ether(4) netgraph node type 45 */ 46 47#include <sys/param.h> 48#include <sys/systm.h> --- 55 unchanged lines hidden (view full) --- 104static ng_rcvmsg_t ng_ether_rcvmsg; 105static ng_shutdown_t ng_ether_shutdown; 106static ng_newhook_t ng_ether_newhook; 107static ng_connect_t ng_ether_connect; 108static ng_rcvdata_t ng_ether_rcvdata; 109static ng_disconnect_t ng_ether_disconnect; 110static int ng_ether_mod_event(module_t mod, int event, void *data); 111 | 41 */ 42 43/* 44 * ng_ether(4) netgraph node type 45 */ 46 47#include <sys/param.h> 48#include <sys/systm.h> --- 55 unchanged lines hidden (view full) --- 104static ng_rcvmsg_t ng_ether_rcvmsg; 105static ng_shutdown_t ng_ether_shutdown; 106static ng_newhook_t ng_ether_newhook; 107static ng_connect_t ng_ether_connect; 108static ng_rcvdata_t ng_ether_rcvdata; 109static ng_disconnect_t ng_ether_disconnect; 110static int ng_ether_mod_event(module_t mod, int event, void *data); 111 |
112/* Parse type for an Ethernet address */ 113static ng_parse_t ng_enaddr_parse; 114static ng_unparse_t ng_enaddr_unparse; 115const struct ng_parse_type ng_ether_enaddr_type = { 116 NULL, 117 NULL, 118 NULL, 119 ng_enaddr_parse, 120 ng_enaddr_unparse, 121 NULL, /* no such thing as a "default" EN address */ 122 0 123}; 124 | |
125/* List of commands and how to convert arguments to/from ASCII */ 126static const struct ng_cmdlist ng_ether_cmdlist[] = { 127 { 128 NGM_ETHER_COOKIE, 129 NGM_ETHER_GET_IFNAME, 130 "getifname", 131 NULL, 132 &ng_parse_string_type --- 5 unchanged lines hidden (view full) --- 138 NULL, 139 &ng_parse_int32_type 140 }, 141 { 142 NGM_ETHER_COOKIE, 143 NGM_ETHER_GET_ENADDR, 144 "getenaddr", 145 NULL, | 112/* List of commands and how to convert arguments to/from ASCII */ 113static const struct ng_cmdlist ng_ether_cmdlist[] = { 114 { 115 NGM_ETHER_COOKIE, 116 NGM_ETHER_GET_IFNAME, 117 "getifname", 118 NULL, 119 &ng_parse_string_type --- 5 unchanged lines hidden (view full) --- 125 NULL, 126 &ng_parse_int32_type 127 }, 128 { 129 NGM_ETHER_COOKIE, 130 NGM_ETHER_GET_ENADDR, 131 "getenaddr", 132 NULL, |
146 &ng_ether_enaddr_type | 133 &ng_parse_enaddr_type |
147 }, 148 { 149 NGM_ETHER_COOKIE, 150 NGM_ETHER_SET_ENADDR, 151 "setenaddr", | 134 }, 135 { 136 NGM_ETHER_COOKIE, 137 NGM_ETHER_SET_ENADDR, 138 "setenaddr", |
152 &ng_ether_enaddr_type, | 139 &ng_parse_enaddr_type, |
153 NULL 154 }, 155 { 156 NGM_ETHER_COOKIE, 157 NGM_ETHER_GET_PROMISC, 158 "getpromisc", 159 NULL, 160 &ng_parse_int32_type --- 487 unchanged lines hidden (view full) --- 648 } else 649 panic("%s: weird hook", __func__); 650 if ((NG_NODE_NUMHOOKS(NG_HOOK_NODE(hook)) == 0) 651 && (NG_NODE_IS_VALID(NG_HOOK_NODE(hook)))) 652 ng_rmnode_self(NG_HOOK_NODE(hook)); /* reset node */ 653 return (0); 654} 655 | 140 NULL 141 }, 142 { 143 NGM_ETHER_COOKIE, 144 NGM_ETHER_GET_PROMISC, 145 "getpromisc", 146 NULL, 147 &ng_parse_int32_type --- 487 unchanged lines hidden (view full) --- 635 } else 636 panic("%s: weird hook", __func__); 637 if ((NG_NODE_NUMHOOKS(NG_HOOK_NODE(hook)) == 0) 638 && (NG_NODE_IS_VALID(NG_HOOK_NODE(hook)))) 639 ng_rmnode_self(NG_HOOK_NODE(hook)); /* reset node */ 640 return (0); 641} 642 |
656static int 657ng_enaddr_parse(const struct ng_parse_type *type, 658 const char *s, int *const off, const u_char *const start, 659 u_char *const buf, int *const buflen) 660{ 661 char *eptr; 662 u_long val; 663 int i; 664 665 if (*buflen < ETHER_ADDR_LEN) 666 return (ERANGE); 667 for (i = 0; i < ETHER_ADDR_LEN; i++) { 668 val = strtoul(s + *off, &eptr, 16); 669 if (val > 0xff || eptr == s + *off) 670 return (EINVAL); 671 buf[i] = (u_char)val; 672 *off = (eptr - s); 673 if (i < ETHER_ADDR_LEN - 1) { 674 if (*eptr != ':') 675 return (EINVAL); 676 (*off)++; 677 } 678 } 679 *buflen = ETHER_ADDR_LEN; 680 return (0); 681} 682 683static int 684ng_enaddr_unparse(const struct ng_parse_type *type, 685 const u_char *data, int *off, char *cbuf, int cbuflen) 686{ 687 int len; 688 689 len = snprintf(cbuf, cbuflen, "%02x:%02x:%02x:%02x:%02x:%02x", 690 data[*off], data[*off + 1], data[*off + 2], 691 data[*off + 3], data[*off + 4], data[*off + 5]); 692 if (len >= cbuflen) 693 return (ERANGE); 694 *off += ETHER_ADDR_LEN; 695 return (0); 696} 697 | |
698/****************************************************************** 699 INITIALIZATION 700******************************************************************/ 701 702/* 703 * Handle loading and unloading for this node type. 704 */ 705static int --- 57 unchanged lines hidden --- | 643/****************************************************************** 644 INITIALIZATION 645******************************************************************/ 646 647/* 648 * Handle loading and unloading for this node type. 649 */ 650static int --- 57 unchanged lines hidden --- |