ifclone.c (177799) | ifclone.c (189096) |
---|---|
1/* 2 * Copyright (c) 1983, 1993 3 * The Regents of the University of California. All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 15 unchanged lines hidden (view full) --- 24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27 * SUCH DAMAGE. 28 */ 29 30#ifndef lint 31static const char rcsid[] = | 1/* 2 * Copyright (c) 1983, 1993 3 * The Regents of the University of California. All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 15 unchanged lines hidden (view full) --- 24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27 * SUCH DAMAGE. 28 */ 29 30#ifndef lint 31static const char rcsid[] = |
32 "$FreeBSD: head/sbin/ifconfig/ifclone.c 177799 2008-03-31 15:38:07Z sam $"; | 32 "$FreeBSD: head/sbin/ifconfig/ifclone.c 189096 2009-02-27 00:31:34Z rpaulo $"; |
33#endif /* not lint */ 34 | 33#endif /* not lint */ 34 |
35#include <sys/queue.h> |
|
35#include <sys/types.h> 36#include <sys/ioctl.h> 37#include <sys/socket.h> 38#include <net/if.h> 39 40#include <err.h> 41#include <stdio.h> 42#include <stdlib.h> --- 40 unchanged lines hidden (view full) --- 83 putchar(' '); 84 printf("%s", cp); 85 } 86 87 putchar('\n'); 88 free(buf); 89} 90 | 36#include <sys/types.h> 37#include <sys/ioctl.h> 38#include <sys/socket.h> 39#include <net/if.h> 40 41#include <err.h> 42#include <stdio.h> 43#include <stdlib.h> --- 40 unchanged lines hidden (view full) --- 84 putchar(' '); 85 printf("%s", cp); 86 } 87 88 putchar('\n'); 89 free(buf); 90} 91 |
91static clone_callback_func *clone_cb = NULL; | 92struct clone_defcb { 93 char ifprefix[IFNAMSIZ]; 94 clone_callback_func *clone_cb; 95 SLIST_ENTRY(clone_defcb) next; 96}; |
92 | 97 |
98static SLIST_HEAD(, clone_defcb) clone_defcbh = 99 SLIST_HEAD_INITIALIZER(clone_defcbh); 100 |
|
93void | 101void |
94clone_setcallback(clone_callback_func *p) | 102clone_setdefcallback(const char *ifprefix, clone_callback_func *p) |
95{ | 103{ |
96 if (clone_cb != NULL && clone_cb != p) 97 errx(1, "conflicting device create parameters"); 98 clone_cb = p; | 104 struct clone_defcb *dcp; 105 106 dcp = malloc(sizeof(*dcp)); 107 strlcpy(dcp->ifprefix, ifprefix, IFNAMSIZ-1); 108 dcp->clone_cb = p; 109 SLIST_INSERT_HEAD(&clone_defcbh, dcp, next); |
99} 100 101/* 102 * Do the actual clone operation. Any parameters must have been 103 * setup by now. If a callback has been setup to do the work 104 * then defer to it; otherwise do a simple create operation with 105 * no parameters. 106 */ 107static void 108ifclonecreate(int s, void *arg) 109{ 110 struct ifreq ifr; | 110} 111 112/* 113 * Do the actual clone operation. Any parameters must have been 114 * setup by now. If a callback has been setup to do the work 115 * then defer to it; otherwise do a simple create operation with 116 * no parameters. 117 */ 118static void 119ifclonecreate(int s, void *arg) 120{ 121 struct ifreq ifr; |
122 struct clone_defcb *dcp; 123 clone_callback_func *clone_cb = NULL; |
|
111 112 memset(&ifr, 0, sizeof(ifr)); 113 (void) strlcpy(ifr.ifr_name, name, sizeof(ifr.ifr_name)); | 124 125 memset(&ifr, 0, sizeof(ifr)); 126 (void) strlcpy(ifr.ifr_name, name, sizeof(ifr.ifr_name)); |
127 |
|
114 if (clone_cb == NULL) { | 128 if (clone_cb == NULL) { |
129 /* Try to find a default callback */ 130 SLIST_FOREACH(dcp, &clone_defcbh, next) { 131 if (strncmp(dcp->ifprefix, ifr.ifr_name, 132 strlen(dcp->ifprefix)) == 0) { 133 clone_cb = dcp->clone_cb; 134 break; 135 } 136 } 137 } 138 if (clone_cb == NULL) { |
|
115 /* NB: no parameters */ 116 if (ioctl(s, SIOCIFCREATE2, &ifr) < 0) 117 err(1, "SIOCIFCREATE2"); 118 } else { 119 clone_cb(s, &ifr); 120 } 121 122 /* --- 48 unchanged lines hidden --- | 139 /* NB: no parameters */ 140 if (ioctl(s, SIOCIFCREATE2, &ifr) < 0) 141 err(1, "SIOCIFCREATE2"); 142 } else { 143 clone_cb(s, &ifr); 144 } 145 146 /* --- 48 unchanged lines hidden --- |