1 /*- 2 * SPDX-License-Identifier: BSD-2-Clause 3 * 4 * Copyright (c) 2008 Isilon Inc http://www.isilon.com/ 5 * Authors: Doug Rabson <dfr@rabson.org> 6 * Developed with Red Inc: Alfred Perlstein <alfred@freebsd.org> 7 * 8 * Redistribution and use in source and binary forms, with or without 9 * modification, are permitted provided that the following conditions 10 * are met: 11 * 1. Redistributions of source code must retain the above copyright 12 * notice, this list of conditions and the following disclaimer. 13 * 2. Redistributions in binary form must reproduce the above copyright 14 * notice, this list of conditions and the following disclaimer in the 15 * documentation and/or other materials provided with the distribution. 16 * 17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 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 #include "opt_inet6.h" 31 32 #include <sys/cdefs.h> 33 #include <sys/param.h> 34 #include <sys/malloc.h> 35 #include <sys/systm.h> 36 37 #include <rpc/types.h> 38 39 /* 40 * For in-kernel use, we use a simple compiled-in configuration. 41 */ 42 43 static struct netconfig netconfigs[] = { 44 #ifdef INET6 45 { 46 .nc_netid = "udp6", 47 .nc_semantics = NC_TPI_CLTS, 48 .nc_flag = NC_VISIBLE, 49 .nc_protofmly = "inet6", 50 .nc_proto = "udp", 51 }, 52 { 53 .nc_netid = "tcp6", 54 .nc_semantics = NC_TPI_COTS_ORD, 55 .nc_flag = NC_VISIBLE, 56 .nc_protofmly = "inet6", 57 .nc_proto = "tcp", 58 }, 59 #endif 60 { 61 .nc_netid = "udp", 62 .nc_semantics = NC_TPI_CLTS, 63 .nc_flag = NC_VISIBLE, 64 .nc_protofmly = "inet", 65 .nc_proto = "udp", 66 }, 67 { 68 .nc_netid = "tcp", 69 .nc_semantics = NC_TPI_COTS_ORD, 70 .nc_flag = NC_VISIBLE, 71 .nc_protofmly = "inet", 72 .nc_proto = "tcp", 73 }, 74 { 75 .nc_netid = "local", 76 .nc_semantics = NC_TPI_COTS_ORD, 77 .nc_flag = 0, 78 .nc_protofmly = "loopback", 79 .nc_proto = "", 80 }, 81 { 82 .nc_netid = NULL, 83 } 84 }; 85 86 void * 87 setnetconfig(void) 88 { 89 struct netconfig **nconfp; 90 91 nconfp = malloc(sizeof(struct netconfig *), M_RPC, M_WAITOK); 92 *nconfp = netconfigs; 93 94 return ((void *) nconfp); 95 } 96 97 struct netconfig * 98 getnetconfig(void *handle) 99 { 100 struct netconfig **nconfp = (struct netconfig **) handle; 101 struct netconfig *nconf; 102 103 nconf = *nconfp; 104 if (nconf->nc_netid == NULL) 105 return (NULL); 106 107 (*nconfp)++; 108 109 return (nconf); 110 } 111 112 struct netconfig * 113 getnetconfigent(const char *netid) 114 { 115 struct netconfig *nconf; 116 117 for (nconf = netconfigs; nconf->nc_netid; nconf++) { 118 if (!strcmp(netid, nconf->nc_netid)) 119 return (nconf); 120 } 121 122 return (NULL); 123 } 124 125 void 126 freenetconfigent(struct netconfig *nconf) 127 { 128 129 } 130 131 int 132 endnetconfig(void * handle) 133 { 134 struct netconfig **nconfp = (struct netconfig **) handle; 135 136 free(nconfp, M_RPC); 137 return (0); 138 } 139