[331] | 1 | /*
|
---|
| 2 | * TINET (TCP/IP Protocol Stack)
|
---|
| 3 | *
|
---|
| 4 | * Copyright (C) 2001-2017 by Dep. of Computer Science and Engineering
|
---|
| 5 | * Tomakomai National College of Technology, JAPAN
|
---|
| 6 | *
|
---|
| 7 | * ä¸è¨èä½æ¨©è
|
---|
| 8 | ã¯ï¼ä»¥ä¸ã® (1)ï½(4) ã®æ¡ä»¶ãï¼Free Software Foundation
|
---|
| 9 | * ã«ãã£ã¦å
|
---|
| 10 | ¬è¡¨ããã¦ãã GNU General Public License ã® Version 2 ã«è¨
|
---|
| 11 | * è¿°ããã¦ããæ¡ä»¶ãæºããå ´åã«éãï¼æ¬ã½ããã¦ã§ã¢ï¼æ¬ã½ããã¦ã§ã¢
|
---|
| 12 | * ãæ¹å¤ãããã®ãå«ãï¼ä»¥ä¸åãï¼ã使ç¨ã»è¤è£½ã»æ¹å¤ã»åé
|
---|
| 13 | å¸ï¼ä»¥ä¸ï¼
|
---|
| 14 | * å©ç¨ã¨å¼ã¶ï¼ãããã¨ãç¡åã§è¨±è«¾ããï¼
|
---|
| 15 | * (1) æ¬ã½ããã¦ã§ã¢ãã½ã¼ã¹ã³ã¼ãã®å½¢ã§å©ç¨ããå ´åã«ã¯ï¼ä¸è¨ã®èä½
|
---|
| 16 | * 権表示ï¼ãã®å©ç¨æ¡ä»¶ããã³ä¸è¨ã®ç¡ä¿è¨¼è¦å®ãï¼ãã®ã¾ã¾ã®å½¢ã§ã½ã¼
|
---|
| 17 | * ã¹ã³ã¼ãä¸ã«å«ã¾ãã¦ãããã¨ï¼
|
---|
| 18 | * (2) æ¬ã½ããã¦ã§ã¢ãï¼ã©ã¤ãã©ãªå½¢å¼ãªã©ï¼ä»ã®ã½ããã¦ã§ã¢éçºã«ä½¿
|
---|
| 19 | * ç¨ã§ããå½¢ã§åé
|
---|
| 20 | å¸ããå ´åã«ã¯ï¼åé
|
---|
| 21 | å¸ã«ä¼´ãããã¥ã¡ã³ãï¼å©ç¨
|
---|
| 22 | * è
|
---|
| 23 | ããã¥ã¢ã«ãªã©ï¼ã«ï¼ä¸è¨ã®èä½æ¨©è¡¨ç¤ºï¼ãã®å©ç¨æ¡ä»¶ããã³ä¸è¨
|
---|
| 24 | * ã®ç¡ä¿è¨¼è¦å®ãæ²è¼ãããã¨ï¼
|
---|
| 25 | * (3) æ¬ã½ããã¦ã§ã¢ãï¼æ©å¨ã«çµã¿è¾¼ããªã©ï¼ä»ã®ã½ããã¦ã§ã¢éçºã«ä½¿
|
---|
| 26 | * ç¨ã§ããªãå½¢ã§åé
|
---|
| 27 | å¸ããå ´åã«ã¯ï¼æ¬¡ã®æ¡ä»¶ãæºãããã¨ï¼
|
---|
| 28 | * (a) åé
|
---|
| 29 | å¸ã«ä¼´ãããã¥ã¡ã³ãï¼å©ç¨è
|
---|
| 30 | ããã¥ã¢ã«ãªã©ï¼ã«ï¼ä¸è¨ã®è
|
---|
| 31 | * ä½æ¨©è¡¨ç¤ºï¼ãã®å©ç¨æ¡ä»¶ããã³ä¸è¨ã®ç¡ä¿è¨¼è¦å®ãæ²è¼ãããã¨ï¼
|
---|
| 32 | * (4) æ¬ã½ããã¦ã§ã¢ã®å©ç¨ã«ããç´æ¥çã¾ãã¯éæ¥çã«çãããããªãæ
|
---|
| 33 | * 害ãããï¼ä¸è¨èä½æ¨©è
|
---|
| 34 | ããã³TOPPERSããã¸ã§ã¯ããå
|
---|
| 35 | 責ãããã¨ï¼
|
---|
| 36 | *
|
---|
| 37 | * æ¬ã½ããã¦ã§ã¢ã¯ï¼ç¡ä¿è¨¼ã§æä¾ããã¦ãããã®ã§ããï¼ä¸è¨èä½æ¨©è
|
---|
| 38 | ã
|
---|
| 39 | * ãã³TOPPERSããã¸ã§ã¯ãã¯ï¼æ¬ã½ããã¦ã§ã¢ã«é¢ãã¦ï¼ãã®é©ç¨å¯è½æ§ã
|
---|
| 40 | * å«ãã¦ï¼ãããªãä¿è¨¼ãè¡ããªãï¼ã¾ãï¼æ¬ã½ããã¦ã§ã¢ã®å©ç¨ã«ããç´
|
---|
| 41 | * æ¥çã¾ãã¯éæ¥çã«çãããããªãæ害ã«é¢ãã¦ãï¼ãã®è²¬ä»»ãè² ããªãï¼
|
---|
| 42 | *
|
---|
| 43 | * @(#) $Id$
|
---|
| 44 | */
|
---|
| 45 |
|
---|
| 46 | /*
|
---|
| 47 | * Copyright (c) 1982, 1986, 1988, 1990, 1993, 1995
|
---|
| 48 | * The Regents of the University of California. All rights reserved.
|
---|
| 49 | *
|
---|
| 50 | * Redistribution and use in source and binary forms, with or without
|
---|
| 51 | * modification, are permitted provided that the following conditions
|
---|
| 52 | * are met:
|
---|
| 53 | * 1. Redistributions of source code must retain the above copyright
|
---|
| 54 | * notice, this list of conditions and the following disclaimer.
|
---|
| 55 | * 2. Redistributions in binary form must reproduce the above copyright
|
---|
| 56 | * notice, this list of conditions and the following disclaimer in the
|
---|
| 57 | * documentation and/or other materials provided with the distribution.
|
---|
| 58 | * 3. All advertising materials mentioning features or use of this software
|
---|
| 59 | * must display the following acknowledgement:
|
---|
| 60 | * This product includes software developed by the University of
|
---|
| 61 | * California, Berkeley and its contributors.
|
---|
| 62 | * 4. Neither the name of the University nor the names of its contributors
|
---|
| 63 | * may be used to endorse or promote products derived from this software
|
---|
| 64 | * without specific prior written permission.
|
---|
| 65 | *
|
---|
| 66 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
---|
| 67 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
---|
| 68 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
---|
| 69 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
---|
| 70 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
---|
| 71 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
---|
| 72 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
---|
| 73 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
---|
| 74 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
---|
| 75 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
---|
| 76 | * SUCH DAMAGE.
|
---|
[429] | 77 | */
|
---|
[331] | 78 |
|
---|
| 79 | #if (API_PROTO == API_PROTO_IPV6) || (TNUM_UDP4_CEPID > 0)
|
---|
[429] | 80 |
|
---|
[331] | 81 | /*
|
---|
| 82 | * udp_input_select -- UDP ã®å
|
---|
| 83 | ¥åå¦çã®é¸æ
|
---|
| 84 | */
|
---|
| 85 |
|
---|
| 86 | void
|
---|
| 87 | UDP_INPUT_SELECT (T_UDP_CEP *cep, T_NET_BUF *input, uint_t off)
|
---|
| 88 | {
|
---|
| 89 | T_UDP_HDR *udph;
|
---|
| 90 | T_UDP_RCV_DAT_PARA para;
|
---|
| 91 |
|
---|
| 92 | udph = (T_UDP_HDR *)(input->buf + off);
|
---|
| 93 | para.len = (uint_t)(ntohs(udph->ulen) - UDP_HDR_SIZE);
|
---|
| 94 |
|
---|
| 95 | if (cep->rcv_tskid != TA_NULL) { /* éãã³ããããã³ã°ã³ã¼ã«ã§ãã³ãã£ã³ã°ä¸ */
|
---|
| 96 | if (psnd_dtq(cep->rcvqid, (intptr_t)input) != E_OK) {
|
---|
| 97 | NET_COUNT_UDP(net_count_udp.in_err_packets, 1);
|
---|
| 98 | NET_COUNT_MIB(udp_stats.udpInErrors, 1);
|
---|
| 99 | syscall(rel_net_buf(input));
|
---|
[429] | 100 | }
|
---|
[331] | 101 | }
|
---|
| 102 |
|
---|
| 103 | #ifdef UDP_CFG_NON_BLOCKING
|
---|
| 104 |
|
---|
| 105 | else if (cep->rcv_p_dstaddr != NULL) { /* ãã³ããããã³ã°ã³ã¼ã«ã§ãã³ãã£ã³ã°ä¸ */
|
---|
[429] | 106 |
|
---|
[331] | 107 | /* p_dstaddr ãè¨å®ããã*/
|
---|
[429] | 108 | cep->rcv_p_dstaddr->portno = ntohs(udph->sport);
|
---|
[331] | 109 | IN_COPY_TO_HOST(&cep->rcv_p_dstaddr->ipaddr, input);
|
---|
| 110 |
|
---|
| 111 | /* ãã¼ã¿ããããã¡ã«ç§»ãã*/
|
---|
| 112 | memcpy(cep->rcv_data, GET_UDP_SDU(input, off),
|
---|
| 113 | (size_t)(para.len < cep->rcv_len ? para.len : cep->rcv_len));
|
---|
| 114 | syscall(rel_net_buf(input));
|
---|
| 115 |
|
---|
| 116 | if (IS_PTR_DEFINED(cep->callback))
|
---|
| 117 |
|
---|
| 118 | #ifdef TCP_CFG_NON_BLOCKING_COMPAT14
|
---|
| 119 | (*cep->callback)(GET_UDP_CEPID(cep), TFN_UDP_RCV_DAT, (void*)(uint32_t)para.len);
|
---|
| 120 | #else
|
---|
| 121 | (*cep->callback)(GET_UDP_CEPID(cep), TFN_UDP_RCV_DAT, (void*)¶.len);
|
---|
| 122 | #endif
|
---|
[429] | 123 | else
|
---|
[331] | 124 | syslog(LOG_WARNING, "[UDP] no call back, CEP: %d.", GET_UDP_CEPID(cep));
|
---|
[429] | 125 | cep->rcv_p_dstaddr = NULL;
|
---|
| 126 | }
|
---|
| 127 |
|
---|
| 128 | #endif/* of #ifdef UDP_CFG_NON_BLOCKING */
|
---|
| 129 |
|
---|
| 130 | else if (IS_PTR_DEFINED(cep->callback)) {
|
---|
| 131 |
|
---|
| 132 | /* ã³ã¼ã«ããã¯é¢æ°ãå¼ã³åºãã*/
|
---|
[331] | 133 | cep->cb_netbuf = input;
|
---|
[429] | 134 |
|
---|
| 135 | #ifdef TCP_CFG_NON_BLOCKING_COMPAT14
|
---|
[331] | 136 | (*cep->callback)(GET_UDP_CEPID(cep), TEV_UDP_RCV_DAT, (void*)(uint32_t)para.len);
|
---|
| 137 | #else
|
---|
| 138 | para.input = input;
|
---|
| 139 | para.off = off;
|
---|
[429] | 140 | #if API_PROTO == API_PROTO_IPV4
|
---|
| 141 | para.rep4.portno = ntohs(udph->sport);
|
---|
| 142 | IN_COPY_TO_HOST(¶.rep4.ipaddr, input);
|
---|
| 143 | #else
|
---|
| 144 | para.rep6.portno = ntohs(udph->sport);
|
---|
[331] | 145 | IN_COPY_TO_HOST(¶.rep6.ipaddr, input);
|
---|
| 146 | #endif
|
---|
| 147 | (*cep->callback)(GET_UDP_CEPID(cep), TEV_UDP_RCV_DAT, (void*)¶.len);
|
---|
| 148 | #endif
|
---|
| 149 | /*
|
---|
| 150 | * ãããã¯ã¼ã¯ãããã¡ããã®ã¾ã¾ã§ããã°ãã³ã¼ã«ããã¯é¢æ°å
|
---|
| 151 | ã§
|
---|
| 152 | * ãã¼ã¿ãèªã¿åºããªãã£ããã¨ã«ãªãã®ã§ãæ¨ã¦ãã
|
---|
| 153 | */
|
---|
| 154 | if (cep->cb_netbuf != NULL) {
|
---|
| 155 | if ((input->flags & NB_FLG_NOREL_IFOUT) == 0)
|
---|
| 156 | syscall(rel_net_buf(cep->cb_netbuf));
|
---|
| 157 | cep->cb_netbuf = NULL;
|
---|
| 158 | }
|
---|
| 159 | }
|
---|
| 160 | else {
|
---|
| 161 | NET_COUNT_UDP(net_count_udp.in_err_packets, 1);
|
---|
| 162 | NET_COUNT_MIB(udp_stats.udpInErrors, 1);
|
---|
| 163 | syscall(rel_net_buf(input));
|
---|
| 164 | }
|
---|
| 165 |
|
---|
| 166 | }
|
---|
| 167 |
|
---|
| 168 | #endif /* of #if (API_PROTO == API_PROTO_IPV6) || (TNUM_UDP4_CEPID > 0) */
|
---|
| 169 |
|
---|
| 170 | /*
|
---|
| 171 | * udp_input -- UDP ã®å
|
---|
| 172 | ¥åé¢æ°
|
---|
| 173 | */
|
---|
| 174 |
|
---|
| 175 | uint_t
|
---|
| 176 | UDP_INPUT (T_NET_BUF **inputp, uint_t *offp, uint_t *nextp)
|
---|
| 177 | {
|
---|
| 178 | T_NET_BUF *input = *inputp;
|
---|
| 179 | T_UDP_CEP *cep;
|
---|
| 180 | T_UDP_HDR *udph;
|
---|
| 181 | uint_t hlen, ulen;
|
---|
| 182 |
|
---|
| 183 | #if defined(_IP6_CFG) && defined(_IP4_CFG) && API_PROTO == API_PROTO_IPV4
|
---|
| 184 | T_UDP6_CEP *cep6;
|
---|
| 185 | #endif
|
---|
| 186 |
|
---|
| 187 | hlen = (uint_t)GET_IF_IP_HDR_SIZE(input);
|
---|
| 188 |
|
---|
| 189 | NET_COUNT_UDP(net_count_udp.in_octets, input->len - hlen);
|
---|
| 190 | NET_COUNT_UDP(net_count_udp.in_packets, 1);
|
---|
| 191 | NET_COUNT_MIB(udp_stats.udpInDatagrams, 1);
|
---|
| 192 |
|
---|
| 193 | /* ãããé·ããã§ãã¯ããã*/
|
---|
| 194 | if (input->len < hlen + UDP_HDR_SIZE)
|
---|
| 195 | goto buf_rel;
|
---|
| 196 |
|
---|
| 197 | udph = (T_UDP_HDR *)(input->buf + *offp);
|
---|
| 198 |
|
---|
| 199 | /* ãã¼ã¿ã°ã©ã é·ããã§ãã¯ãã */
|
---|
| 200 | ulen = ntohs(udph->ulen);
|
---|
| 201 | if (ulen != input->len - hlen)
|
---|
| 202 | goto buf_rel;
|
---|
| 203 |
|
---|
| 204 | /* å®å
|
---|
| 205 | ãã¼ãã 0 ã®ãã¼ã¿ã°ã©ã ã¯ç ´æ£ãããRFC768 */
|
---|
| 206 | if (udph->dport == 0)
|
---|
| 207 | goto buf_rel;
|
---|
| 208 |
|
---|
| 209 | #ifdef UDP_CFG_IN_CHECKSUM
|
---|
| 210 |
|
---|
| 211 | /* ãã§ãã¯ãµã ããã§ãã¯ãã */
|
---|
| 212 | if (udph->sum && IN_CKSUM(input, IPPROTO_UDP, *offp, ulen) != 0)
|
---|
| 213 | goto buf_rel;
|
---|
| 214 |
|
---|
| 215 | #endif /* of #ifdef UDP_CFG_IN_CHECKSUM */
|
---|
| 216 |
|
---|
| 217 | #if defined(_IP6_CFG) && defined(_IP4_CFG) && API_PROTO == API_PROTO_IPV4
|
---|
| 218 |
|
---|
| 219 | #if TNUM_UDP4_CEPID > 0
|
---|
| 220 |
|
---|
| 221 | /* UDP é信端ç¹ãå¾ãã*/
|
---|
| 222 | cep = udp4_find_cep(input, *offp);
|
---|
| 223 |
|
---|
| 224 | if (cep != NULL)
|
---|
| 225 | udp4_input_select(cep, input, *offp);
|
---|
| 226 | else if ((cep6 = udp6_find_cep(input, *offp)) != NULL)
|
---|
| 227 | udp6_input_select(cep6, input, *offp);
|
---|
| 228 | else
|
---|
| 229 | udp4_reply_no_port(input, *offp);
|
---|
| 230 |
|
---|
| 231 | return IPPROTO_DONE;
|
---|
| 232 |
|
---|
| 233 | #else /* of #if TNUM_UDP4_CEPID > 0 */
|
---|
| 234 |
|
---|
| 235 | cep = 0; /* warning åé¿ç¨ã®ããã¼ */
|
---|
| 236 | if ((cep6 = udp6_find_cep(input, *offp)) != NULL)
|
---|
| 237 | udp6_input_select(cep6, input, *offp);
|
---|
| 238 | else
|
---|
| 239 | udp4_reply_no_port(input, *offp);
|
---|
| 240 |
|
---|
| 241 | return IPPROTO_DONE;
|
---|
| 242 |
|
---|
| 243 | #endif /* of #if TNUM_UDP4_CEPID > 0 */
|
---|
| 244 |
|
---|
| 245 | #else /* of #if defined(_IP6_CFG) && defined(_IP4_CFG) && API_PROTO == API_PROTO_IPV4 */
|
---|
| 246 |
|
---|
| 247 | /* UDP é信端ç¹ãå¾ãã*/
|
---|
| 248 | cep = UDP_FIND_CEP(input, *offp);
|
---|
| 249 |
|
---|
| 250 | if (cep != NULL)
|
---|
| 251 | UDP_INPUT_SELECT(cep, input, *offp);
|
---|
| 252 | else
|
---|
| 253 | UDP_REPLY_NO_PORT(input, *offp);
|
---|
| 254 |
|
---|
| 255 | return IPPROTO_DONE;
|
---|
| 256 |
|
---|
| 257 | #endif /* of #if defined(_IP6_CFG) && defined(_IP4_CFG) && API_PROTO == API_PROTO_IPV4 */
|
---|
| 258 |
|
---|
| 259 | buf_rel:
|
---|
| 260 | NET_COUNT_UDP(net_count_udp.in_err_packets, 1);
|
---|
| 261 | NET_COUNT_MIB(udp_stats.udpInErrors, 1);
|
---|
| 262 | syscall(rel_net_buf(input));
|
---|
| 263 | return IPPROTO_DONE;
|
---|
| 264 | }
|
---|