mpls_raw.c 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. /* $OpenBSD: mpls_raw.c,v 1.12 2015/07/20 21:16:39 rzalamena Exp $ */
  2. /*
  3. * Copyright (C) 1999, 2000 and 2001 AYAME Project, WIDE Project.
  4. * All rights reserved.
  5. *
  6. * Redistribution and use in source and binary forms, with or without
  7. * modification, are permitted provided that the following conditions
  8. * are met:
  9. *
  10. * 1. Redistributions of source code must retain the above copyright
  11. * notice, this list of conditions and the following disclaimer.
  12. * 2. Redistributions in binary form must reproduce the above copyright
  13. * notice, this list of conditions and the following disclaimer in the
  14. * documentation and/or other materials provided with the distribution.
  15. * 3. Neither the name of the project nor the names of its contributors
  16. * may be used to endorse or promote products derived from this software
  17. * without specific prior written permission.
  18. *
  19. * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
  20. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  21. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  22. * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
  23. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  24. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  25. * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  26. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  27. * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  28. * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  29. * SUCH DAMAGE.
  30. */
  31. #include <sys/param.h>
  32. #include <sys/mbuf.h>
  33. #include <sys/errno.h>
  34. #include <sys/protosw.h>
  35. #include <sys/sockio.h>
  36. #include <sys/socket.h>
  37. #include <sys/socketvar.h>
  38. #include <sys/systm.h>
  39. #include <sys/sysctl.h>
  40. #include <net/if.h>
  41. #include <net/if_var.h>
  42. #include <net/if_types.h>
  43. #include <netmpls/mpls.h>
  44. #define MPLS_RAW_SNDQ 8192
  45. #define MPLS_RAW_RCVQ 8192
  46. u_long mpls_raw_sendspace = MPLS_RAW_SNDQ;
  47. u_long mpls_raw_recvspace = MPLS_RAW_RCVQ;
  48. int mpls_defttl = 255;
  49. int mpls_inkloop = MPLS_INKERNEL_LOOP_MAX;
  50. int mpls_push_expnull_ip = 0;
  51. int mpls_push_expnull_ip6 = 0;
  52. int mpls_mapttl_ip = 1;
  53. int mpls_mapttl_ip6 = 0;
  54. int *mplsctl_vars[MPLSCTL_MAXID] = MPLSCTL_VARS;
  55. int mpls_control(struct socket *, u_long, caddr_t, struct ifnet *);
  56. /*
  57. * Generic MPLS control operations (ioctl's).
  58. * Ifp is 0 if not an interface-specific ioctl.
  59. */
  60. /* ARGSUSED */
  61. int
  62. mpls_control(struct socket *so, u_long cmd, caddr_t data, struct ifnet *ifp)
  63. {
  64. return (EOPNOTSUPP);
  65. }
  66. int
  67. mpls_raw_usrreq(struct socket *so, int req, struct mbuf *m, struct mbuf *nam,
  68. struct mbuf *control, struct proc *p)
  69. {
  70. int error = 0;
  71. #ifdef MPLS_DEBUG
  72. printf("mpls_raw_usrreq: called! (reqid=%d).\n", req);
  73. #endif /* MPLS_DEBUG */
  74. if (req == PRU_CONTROL)
  75. return (mpls_control(so, (u_long)m, (caddr_t)nam,
  76. (struct ifnet *)control));
  77. switch (req) {
  78. case PRU_ATTACH:
  79. if (so->so_snd.sb_hiwat == 0 || so->so_rcv.sb_hiwat == 0) {
  80. error = soreserve(so, mpls_raw_sendspace,
  81. mpls_raw_recvspace);
  82. if (error)
  83. break;
  84. }
  85. break;
  86. case PRU_DETACH:
  87. case PRU_BIND:
  88. case PRU_LISTEN:
  89. case PRU_CONNECT:
  90. case PRU_CONNECT2:
  91. case PRU_DISCONNECT:
  92. case PRU_SHUTDOWN:
  93. case PRU_RCVD:
  94. case PRU_SEND:
  95. case PRU_SENSE:
  96. case PRU_RCVOOB:
  97. case PRU_SENDOOB:
  98. case PRU_SOCKADDR:
  99. case PRU_PEERADDR:
  100. error = EOPNOTSUPP;
  101. break;
  102. default:
  103. panic("mpls_raw_usrreq");
  104. }
  105. return (error);
  106. }
  107. int
  108. mpls_sysctl(int *name, u_int namelen, void *oldp, size_t *oldlenp, void *newp,
  109. size_t newlen)
  110. {
  111. if (name[0] >= MPLSCTL_MAXID)
  112. return (EOPNOTSUPP);
  113. /* Almost all sysctl names at this level are terminal. */
  114. if (namelen != 1)
  115. return (ENOTDIR);
  116. switch (name[0]) {
  117. default:
  118. return sysctl_int_arr(mplsctl_vars, name, namelen,
  119. oldp, oldlenp, newp, newlen);
  120. }
  121. }