getnetconfig.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. /*-
  2. * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
  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. #include "opt_inet6.h"
  30. #include <sys/cdefs.h>
  31. __FBSDID("$FreeBSD$");
  32. #include <sys/param.h>
  33. #include <sys/malloc.h>
  34. #include <sys/systm.h>
  35. #include <rpc/types.h>
  36. /*
  37. * For in-kernel use, we use a simple compiled-in configuration.
  38. */
  39. static struct netconfig netconfigs[] = {
  40. #ifdef INET6
  41. {
  42. .nc_netid = "udp6",
  43. .nc_semantics = NC_TPI_CLTS,
  44. .nc_flag = NC_VISIBLE,
  45. .nc_protofmly = "inet6",
  46. .nc_proto = "udp",
  47. },
  48. {
  49. .nc_netid = "tcp6",
  50. .nc_semantics = NC_TPI_COTS_ORD,
  51. .nc_flag = NC_VISIBLE,
  52. .nc_protofmly = "inet6",
  53. .nc_proto = "tcp",
  54. },
  55. #endif
  56. {
  57. .nc_netid = "udp",
  58. .nc_semantics = NC_TPI_CLTS,
  59. .nc_flag = NC_VISIBLE,
  60. .nc_protofmly = "inet",
  61. .nc_proto = "udp",
  62. },
  63. {
  64. .nc_netid = "tcp",
  65. .nc_semantics = NC_TPI_COTS_ORD,
  66. .nc_flag = NC_VISIBLE,
  67. .nc_protofmly = "inet",
  68. .nc_proto = "tcp",
  69. },
  70. {
  71. .nc_netid = "local",
  72. .nc_semantics = NC_TPI_COTS_ORD,
  73. .nc_flag = 0,
  74. .nc_protofmly = "loopback",
  75. .nc_proto = "",
  76. },
  77. {
  78. .nc_netid = NULL,
  79. }
  80. };
  81. void *
  82. setnetconfig(void)
  83. {
  84. struct netconfig **nconfp;
  85. nconfp = malloc(sizeof(struct netconfig *), M_RPC, M_WAITOK);
  86. *nconfp = netconfigs;
  87. return ((void *) nconfp);
  88. }
  89. struct netconfig *
  90. getnetconfig(void *handle)
  91. {
  92. struct netconfig **nconfp = (struct netconfig **) handle;
  93. struct netconfig *nconf;
  94. nconf = *nconfp;
  95. if (nconf->nc_netid == NULL)
  96. return (NULL);
  97. (*nconfp)++;
  98. return (nconf);
  99. }
  100. struct netconfig *
  101. getnetconfigent(const char *netid)
  102. {
  103. struct netconfig *nconf;
  104. for (nconf = netconfigs; nconf->nc_netid; nconf++) {
  105. if (!strcmp(netid, nconf->nc_netid))
  106. return (nconf);
  107. }
  108. return (NULL);
  109. }
  110. void
  111. freenetconfigent(struct netconfig *nconf)
  112. {
  113. }
  114. int
  115. endnetconfig(void * handle)
  116. {
  117. struct netconfig **nconfp = (struct netconfig **) handle;
  118. free(nconfp, M_RPC);
  119. return (0);
  120. }