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/param.h> 33 #include <sys/malloc.h> 34 #include <sys/systm.h> 35 36 #include <rpc/types.h> 37 38 /* 39 * For in-kernel use, we use a simple compiled-in configuration. 40 */ 41 42 static struct netconfig netconfigs[] = { 43 #ifdef INET6 44 { 45 .nc_netid = "udp6", 46 .nc_semantics = NC_TPI_CLTS, 47 .nc_flag = NC_VISIBLE, 48 .nc_protofmly = "inet6", 49 .nc_proto = "udp", 50 }, 51 { 52 .nc_netid = "tcp6", 53 .nc_semantics = NC_TPI_COTS_ORD, 54 .nc_flag = NC_VISIBLE, 55 .nc_protofmly = "inet6", 56 .nc_proto = "tcp", 57 }, 58 { 59 .nc_netid = "rdma6", 60 .nc_semantics = NC_TPI_COTS_ORD, 61 .nc_flag = NC_VISIBLE, 62 .nc_protofmly = "inet6", 63 .nc_proto = "rdma", 64 }, 65 #endif 66 { 67 .nc_netid = "udp", 68 .nc_semantics = NC_TPI_CLTS, 69 .nc_flag = NC_VISIBLE, 70 .nc_protofmly = "inet", 71 .nc_proto = "udp", 72 }, 73 { 74 .nc_netid = "tcp", 75 .nc_semantics = NC_TPI_COTS_ORD, 76 .nc_flag = NC_VISIBLE, 77 .nc_protofmly = "inet", 78 .nc_proto = "tcp", 79 }, 80 { 81 .nc_netid = "rdma", 82 .nc_semantics = NC_TPI_COTS_ORD, 83 .nc_flag = NC_VISIBLE, 84 .nc_protofmly = "inet", 85 .nc_proto = "rdma", 86 }, 87 { 88 .nc_netid = "local", 89 .nc_semantics = NC_TPI_COTS_ORD, 90 .nc_flag = 0, 91 .nc_protofmly = "loopback", 92 .nc_proto = "", 93 }, 94 { 95 .nc_netid = NULL, 96 } 97 }; 98 99 void * 100 setnetconfig(void) 101 { 102 struct netconfig **nconfp; 103 104 nconfp = malloc(sizeof(struct netconfig *), M_RPC, M_WAITOK); 105 *nconfp = netconfigs; 106 107 return ((void *) nconfp); 108 } 109 110 struct netconfig * 111 getnetconfig(void *handle) 112 { 113 struct netconfig **nconfp = (struct netconfig **) handle; 114 struct netconfig *nconf; 115 116 nconf = *nconfp; 117 if (nconf->nc_netid == NULL) 118 return (NULL); 119 120 (*nconfp)++; 121 122 return (nconf); 123 } 124 125 struct netconfig * 126 getnetconfigent(const char *netid) 127 { 128 struct netconfig *nconf; 129 130 for (nconf = netconfigs; nconf->nc_netid; nconf++) { 131 if (!strcmp(netid, nconf->nc_netid)) 132 return (nconf); 133 } 134 135 return (NULL); 136 } 137 138 void 139 freenetconfigent(struct netconfig *nconf) 140 { 141 142 } 143 144 int 145 endnetconfig(void * handle) 146 { 147 struct netconfig **nconfp = (struct netconfig **) handle; 148 149 free(nconfp, M_RPC); 150 return (0); 151 } 152