[270] | 1 | /*
|
---|
| 2 | * TINET (UDP/IP Protocol Stack)
|
---|
| 3 | *
|
---|
| 4 | * Copyright (C) 2001-2009 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: udp_usrreq_nblk.c 270 2017-02-09 04:03:47Z coas-nagasima $
|
---|
| 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 ceproduce 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.
|
---|
| 77 | *
|
---|
| 78 | * @(#)udp_usrreq.c 8.6 (Berkeley) 5/23/95
|
---|
| 79 | * $FreeBSD: src/sys/netinet/udp_usrreq.c,v 1.49.2.2 1999/08/29 16:29:58 peter Exp $
|
---|
| 80 | */
|
---|
| 81 |
|
---|
| 82 | #include <string.h>
|
---|
| 83 |
|
---|
| 84 | #ifdef TARGET_KERNEL_ASP
|
---|
| 85 |
|
---|
| 86 | #include <kernel.h>
|
---|
| 87 | #include <sil.h>
|
---|
| 88 | #include "kernel_cfg.h"
|
---|
| 89 |
|
---|
| 90 | #endif /* of #ifdef TARGET_KERNEL_ASP */
|
---|
| 91 |
|
---|
| 92 | #ifdef TARGET_KERNEL_JSP
|
---|
| 93 |
|
---|
| 94 | #include <s_services.h>
|
---|
| 95 | #include <t_services.h>
|
---|
| 96 | #include "kernel_id.h"
|
---|
| 97 |
|
---|
| 98 | #endif /* of #ifdef TARGET_KERNEL_JSP */
|
---|
| 99 |
|
---|
| 100 | #include <tinet_defs.h>
|
---|
| 101 | #include <tinet_config.h>
|
---|
| 102 |
|
---|
| 103 | #include <net/if.h>
|
---|
| 104 | #include <net/if_ppp.h>
|
---|
| 105 | #include <net/if_loop.h>
|
---|
| 106 | #include <net/ethernet.h>
|
---|
| 107 | #include <net/net.h>
|
---|
| 108 | #include <net/net_buf.h>
|
---|
| 109 | #include <net/net_count.h>
|
---|
| 110 | #include <net/ppp_ipcp.h>
|
---|
| 111 |
|
---|
| 112 | #include <netinet/in.h>
|
---|
| 113 | #include <netinet6/in6.h>
|
---|
| 114 | #include <netinet/in_var.h>
|
---|
| 115 | #include <netinet/in_itron.h>
|
---|
| 116 | #include <netinet/ip.h>
|
---|
| 117 | #include <netinet/ip_var.h>
|
---|
| 118 | #include <netinet/ip_icmp.h>
|
---|
| 119 | #include <netinet6/in6_var.h>
|
---|
| 120 | #include <netinet/ip6.h>
|
---|
| 121 | #include <netinet6/ip6_var.h>
|
---|
| 122 | #include <netinet6/nd6.h>
|
---|
| 123 | #include <netinet/icmp6.h>
|
---|
| 124 | #include <netinet/udp.h>
|
---|
| 125 | #include <netinet/udp_var.h>
|
---|
| 126 |
|
---|
| 127 | #ifdef SUPPORT_UDP
|
---|
| 128 |
|
---|
| 129 | /*
|
---|
| 130 | * IPv4 㨠IPv6 ã®åãæ¿ããã¯ã
|
---|
| 131 | */
|
---|
| 132 |
|
---|
| 133 | #if defined(SUPPORT_INET4)
|
---|
| 134 |
|
---|
| 135 | #define UDP_SND_DAT udp_snd_dat
|
---|
| 136 | #define UDP_RCV_DAT udp_rcv_dat
|
---|
| 137 |
|
---|
| 138 | #endif /* of #if defined(SUPPORT_INET4) */
|
---|
| 139 |
|
---|
| 140 | #if defined(SUPPORT_INET6)
|
---|
| 141 |
|
---|
| 142 | #define UDP_SND_DAT udp6_snd_dat
|
---|
| 143 | #define UDP_RCV_DAT udp6_rcv_dat
|
---|
| 144 |
|
---|
| 145 | #endif /* of #if defined(SUPPORT_INET6) */
|
---|
| 146 |
|
---|
| 147 | /*
|
---|
| 148 | * TINET ãã©ã¤ãã©ãªåããªãå ´åã¯ãå
|
---|
| 149 | ¨ã¦ã®æ©è½ã
|
---|
| 150 | * ãªãã¸ã§ã¯ããã¡ã¤ã«ã«åºåããããããã¯ããæå¹ã«ããã
|
---|
| 151 | */
|
---|
| 152 |
|
---|
| 153 | #ifndef UDP_CFG_LIBRARY
|
---|
| 154 |
|
---|
| 155 | #define __udp_can_snd
|
---|
| 156 | #define __udp_can_rcv
|
---|
| 157 | #define __udp_snd_dat
|
---|
| 158 | #define __udp_rcv_dat
|
---|
| 159 |
|
---|
| 160 | #endif /* of #ifndef UDP_CFG_LIBRARY */
|
---|
| 161 |
|
---|
| 162 | #ifdef UDP_CFG_NON_BLOCKING
|
---|
| 163 |
|
---|
| 164 | #ifdef __udp_can_snd
|
---|
| 165 |
|
---|
| 166 | /*
|
---|
| 167 | * udp_can_snd -- ãã³ãã£ã³ã°ãã¦ããéä¿¡ã®ãã£ã³ã»ã«
|
---|
| 168 | */
|
---|
| 169 |
|
---|
| 170 | ER
|
---|
| 171 | udp_can_snd (T_UDP_CEP *cep, ER error)
|
---|
| 172 | {
|
---|
| 173 | if (cep->snd_p_dstaddr != NULL) { /* ãã³ããããã³ã°ã³ã¼ã«ã§ãã³ãã£ã³ã°ä¸ */
|
---|
| 174 | if (IS_PTR_DEFINED(cep->callback))
|
---|
| 175 |
|
---|
| 176 | #ifdef TCP_CFG_NON_BLOCKING_COMPAT14
|
---|
| 177 |
|
---|
| 178 | (*cep->callback)(GET_UDP_CEPID(cep), TFN_UDP_SND_DAT, (void*)error);
|
---|
| 179 |
|
---|
| 180 | #else /* of #ifdef TCP_CFG_NON_BLOCKING_COMPAT14 */
|
---|
| 181 |
|
---|
| 182 | (*cep->callback)(GET_UDP_CEPID(cep), TFN_UDP_SND_DAT, (void*)&error);
|
---|
| 183 |
|
---|
| 184 | #endif /* of #ifdef TCP_CFG_NON_BLOCKING_COMPAT14 */
|
---|
| 185 |
|
---|
| 186 | else
|
---|
| 187 | error = E_OBJ;
|
---|
| 188 | cep->snd_p_dstaddr = NULL;
|
---|
| 189 | }
|
---|
| 190 | else if (cep->snd_tskid != TA_NULL) { /* éãã³ããããã³ã°ã³ã¼ã«ã§ãã³ãã£ã³ã°ä¸ */
|
---|
| 191 |
|
---|
| 192 | #ifdef UDP_CFG_EXTENTIONS
|
---|
| 193 |
|
---|
| 194 | /* å¾
|
---|
| 195 | ã¡ä¸ã«çºçããã¨ã©ã¼æ
|
---|
| 196 | å ±ãè¨å®ããã*/
|
---|
| 197 | cep->error = error;
|
---|
| 198 |
|
---|
| 199 | #endif /* of #ifdef UDP_CFG_EXTENTIONS */
|
---|
| 200 |
|
---|
| 201 | error = rel_wai(cep->snd_tskid);
|
---|
| 202 | cep->snd_tskid = TA_NULL;
|
---|
| 203 | }
|
---|
| 204 | else /* ã©ã¡ãã§ããªããªããã³ãã£ã³ã°ãã¦ããªã */
|
---|
| 205 | error = EV_NOPND;
|
---|
| 206 |
|
---|
| 207 | return error;
|
---|
| 208 | }
|
---|
| 209 |
|
---|
| 210 | #endif /* of #ifdef __udp_can_snd */
|
---|
| 211 |
|
---|
| 212 | #ifdef __udp_can_rcv
|
---|
| 213 |
|
---|
| 214 | /*
|
---|
| 215 | * udp_can_rcv -- ãã³ãã£ã³ã°ãã¦ããåä¿¡ã®ãã£ã³ã»ã«
|
---|
| 216 | */
|
---|
| 217 |
|
---|
| 218 | ER
|
---|
| 219 | udp_can_rcv (T_UDP_CEP *cep, ER error)
|
---|
| 220 | {
|
---|
| 221 | if (cep->rcv_p_dstaddr != NULL) { /* ãã³ããããã³ã°ã³ã¼ã«ã§ãã³ãã£ã³ã°ä¸ */
|
---|
| 222 | if (IS_PTR_DEFINED(cep->callback))
|
---|
| 223 |
|
---|
| 224 | #ifdef TCP_CFG_NON_BLOCKING_COMPAT14
|
---|
| 225 |
|
---|
| 226 | (*cep->callback)(GET_UDP_CEPID(cep), TFN_UDP_RCV_DAT, (void*)error);
|
---|
| 227 |
|
---|
| 228 | #else /* of #ifdef TCP_CFG_NON_BLOCKING_COMPAT14 */
|
---|
| 229 |
|
---|
| 230 | (*cep->callback)(GET_UDP_CEPID(cep), TFN_UDP_RCV_DAT, (void*)&error);
|
---|
| 231 |
|
---|
| 232 | #endif /* of #ifdef TCP_CFG_NON_BLOCKING_COMPAT14 */
|
---|
| 233 |
|
---|
| 234 | else
|
---|
| 235 | error = E_OBJ;
|
---|
| 236 | cep->rcv_p_dstaddr = NULL;
|
---|
| 237 | }
|
---|
| 238 | else if (cep->rcv_tskid != TA_NULL) { /* éãã³ããããã³ã°ã³ã¼ã«ã§ãã³ãã£ã³ã°ä¸ */
|
---|
| 239 |
|
---|
| 240 | #ifdef UDP_CFG_EXTENTIONS
|
---|
| 241 |
|
---|
| 242 | /* å¾
|
---|
| 243 | ã¡ä¸ã«çºçããã¨ã©ã¼æ
|
---|
| 244 | å ±ãè¨å®ããã*/
|
---|
| 245 | cep->error = error;
|
---|
| 246 |
|
---|
| 247 | #endif /* of #ifdef UDP_CFG_EXTENTIONS */
|
---|
| 248 |
|
---|
| 249 | error = rel_wai(cep->rcv_tskid);
|
---|
| 250 | cep->rcv_tskid = TA_NULL;
|
---|
| 251 | }
|
---|
| 252 | else /* ã©ã¡ãã§ããªããªããã³ãã£ã³ã°ãã¦ããªã */
|
---|
| 253 | error = EV_NOPND;
|
---|
| 254 |
|
---|
| 255 | return error;
|
---|
| 256 | }
|
---|
| 257 |
|
---|
| 258 | #endif /* of #ifdef __udp_can_rcv */
|
---|
| 259 |
|
---|
| 260 | #ifdef __udp_snd_dat
|
---|
| 261 |
|
---|
| 262 | /*
|
---|
| 263 | * udp_snd_dat -- ãã±ããã®éä¿¡ãæ¨æºæ©è½ã
|
---|
| 264 | */
|
---|
| 265 |
|
---|
| 266 | ER_UINT
|
---|
| 267 | UDP_SND_DAT (ID cepid, T_IPEP *p_dstaddr, void *data, int_t len, TMO tmout)
|
---|
| 268 | {
|
---|
| 269 | T_UDP_CEP *cep;
|
---|
| 270 | ER error;
|
---|
| 271 |
|
---|
| 272 | /* p_dstaddr ã¾ã㯠data ã NULL ãªãã¨ã©ã¼ */
|
---|
| 273 | if (p_dstaddr == NULL || data == NULL)
|
---|
| 274 | return E_PAR;
|
---|
| 275 |
|
---|
| 276 | /* ãã¼ã¿é·ããã§ãã¯ããã*/
|
---|
| 277 | if (len < 0 || len + IP_HDR_SIZE + UDP_HDR_SIZE > IF_MTU)
|
---|
| 278 | return E_PAR;
|
---|
| 279 |
|
---|
| 280 | /* UDP éä¿¡ç«¯ç¹ ID ããã§ãã¯ããã*/
|
---|
| 281 | if (!VALID_UDP_CEPID(cepid))
|
---|
| 282 | return E_ID;
|
---|
| 283 |
|
---|
| 284 | /* UDP é信端ç¹ãå¾ãã*/
|
---|
| 285 | cep = GET_UDP_CEP(cepid);
|
---|
| 286 |
|
---|
| 287 | /* UDP é信端ç¹ããã§ãã¯ããã*/
|
---|
| 288 | if (!VALID_UDP_CEP(cep))
|
---|
| 289 | return E_NOEXS;
|
---|
| 290 |
|
---|
| 291 | /*
|
---|
| 292 | * èªãã¼ãçªå·ã UDP_PORTANY ãªããèªåã§å²ãå½ã¦ãã
|
---|
| 293 | */
|
---|
| 294 | if (cep->myaddr.portno == UDP_PORTANY) {
|
---|
| 295 | if ((error = udp_alloc_auto_port(cep)) != E_OK)
|
---|
| 296 | return error;
|
---|
| 297 | }
|
---|
| 298 |
|
---|
| 299 | /*
|
---|
| 300 | * ã¿ã¤ã ã¢ã¦ãããã§ãã¯ããã
|
---|
| 301 | */
|
---|
| 302 |
|
---|
| 303 | if (tmout == TMO_NBLK) { /* ãã³ããããã³ã°ã³ã¼ã« */
|
---|
| 304 |
|
---|
| 305 | /* é信端ç¹ãããã¯ããã*/
|
---|
| 306 | syscall(wai_sem(cep->semid_lock));
|
---|
| 307 |
|
---|
| 308 | if (cep->snd_p_dstaddr != NULL) {
|
---|
| 309 |
|
---|
| 310 | /* ãã³ããããã³ã°ã³ã¼ã«ã§ãã³ãã£ã³ã°ä¸ */
|
---|
| 311 | error = E_QOVR;
|
---|
| 312 |
|
---|
| 313 | /* é信端ç¹ãããã¯ã解é¤ããã*/
|
---|
| 314 | syscall(sig_sem(cep->semid_lock));
|
---|
| 315 | }
|
---|
| 316 | else if (cep->snd_tskid != TA_NULL) {
|
---|
| 317 |
|
---|
| 318 | /* éãã³ããããã³ã°ã³ã¼ã«ã§ãã³ãã£ã³ã°ä¸ */
|
---|
| 319 | error = E_OBJ;
|
---|
| 320 |
|
---|
| 321 | /* é信端ç¹ãããã¯ã解é¤ããã*/
|
---|
| 322 | syscall(sig_sem(cep->semid_lock));
|
---|
| 323 | }
|
---|
| 324 | else {
|
---|
| 325 |
|
---|
| 326 | cep->snd_p_dstaddr = p_dstaddr;
|
---|
| 327 | cep->snd_data = data;
|
---|
| 328 | cep->snd_len = len;
|
---|
| 329 |
|
---|
| 330 | /* é信端ç¹ãããã¯ã解é¤ããã*/
|
---|
| 331 | syscall(sig_sem(cep->semid_lock));
|
---|
| 332 |
|
---|
| 333 | cep->flags |= UDP_CEP_FLG_POST_OUTPUT;
|
---|
| 334 | sig_sem(SEM_UDP_POST_OUTPUT);
|
---|
| 335 | error = E_WBLK;
|
---|
| 336 | }
|
---|
| 337 | }
|
---|
| 338 | else { /* éãã³ããããã³ã°ã³ã¼ã« */
|
---|
| 339 |
|
---|
| 340 | /* é信端ç¹ãããã¯ããã*/
|
---|
| 341 | syscall(wai_sem(cep->semid_lock));
|
---|
| 342 |
|
---|
| 343 | if (cep->snd_p_dstaddr != NULL) {
|
---|
| 344 |
|
---|
| 345 | /* ãã³ããããã³ã°ã³ã¼ã«ã§ãã³ãã£ã³ã°ä¸ */
|
---|
| 346 | error = E_OBJ;
|
---|
| 347 |
|
---|
| 348 | /* é信端ç¹ãããã¯ã解é¤ããã*/
|
---|
| 349 | syscall(sig_sem(cep->semid_lock));
|
---|
| 350 | }
|
---|
| 351 | else if (cep->snd_tskid != TA_NULL) {
|
---|
| 352 |
|
---|
| 353 | /* éãã³ããããã³ã°ã³ã¼ã«ã§ãã³ãã£ã³ã°ä¸ */
|
---|
| 354 | error = E_QOVR;
|
---|
| 355 |
|
---|
| 356 | /* é信端ç¹ãããã¯ã解é¤ããã*/
|
---|
| 357 | syscall(sig_sem(cep->semid_lock));
|
---|
| 358 | }
|
---|
| 359 | else {
|
---|
| 360 |
|
---|
| 361 | /* ç¾å¨ã®ã¿ã¹ã¯èå¥åãè¨é²ããã*/
|
---|
| 362 | get_tid(&(cep->snd_tskid));
|
---|
| 363 |
|
---|
| 364 | /* é信端ç¹ãããã¯ã解é¤ããã*/
|
---|
| 365 | syscall(sig_sem(cep->semid_lock));
|
---|
| 366 |
|
---|
| 367 | /* ãã±ãããéä¿¡ããã*/
|
---|
| 368 | error = udp_send_data(cep, p_dstaddr, data, len, tmout);
|
---|
| 369 | }
|
---|
| 370 | }
|
---|
| 371 |
|
---|
| 372 | return error;
|
---|
| 373 | }
|
---|
| 374 |
|
---|
| 375 | #endif /* of #ifdef __udp_snd_dat */
|
---|
| 376 |
|
---|
| 377 | #ifdef __udp_rcv_dat
|
---|
| 378 |
|
---|
| 379 | /*
|
---|
| 380 | * udp_rcv_dat -- ãã±ããã®åä¿¡ãæ¨æºæ©è½ã
|
---|
| 381 | */
|
---|
| 382 |
|
---|
| 383 | ER_UINT
|
---|
| 384 | UDP_RCV_DAT (ID cepid, T_IPEP *p_dstaddr, void *data, int_t len, TMO tmout)
|
---|
| 385 | {
|
---|
| 386 | T_NET_BUF *input;
|
---|
| 387 | T_UDP_CEP *cep;
|
---|
| 388 | T_UDP_HDR *udph;
|
---|
| 389 | ER_UINT error;
|
---|
| 390 | uint_t ulen, uhoff;
|
---|
| 391 |
|
---|
| 392 | /* p_dstaddr ã¾ã㯠data ã NULL ããlen < 0 ãªãã¨ã©ã¼ */
|
---|
| 393 | if (p_dstaddr == NULL || data == NULL || len < 0)
|
---|
| 394 | return E_PAR;
|
---|
| 395 |
|
---|
| 396 | /* UDP éä¿¡ç«¯ç¹ ID ããã§ãã¯ããã*/
|
---|
| 397 | if (!VALID_UDP_CEPID(cepid))
|
---|
| 398 | return E_ID;
|
---|
| 399 |
|
---|
| 400 | /* UDP é信端ç¹ãå¾ãã*/
|
---|
| 401 | cep = GET_UDP_CEP(cepid);
|
---|
| 402 |
|
---|
| 403 | /* UDP é信端ç¹ããã§ãã¯ããã*/
|
---|
| 404 | if (!VALID_UDP_CEP(cep))
|
---|
| 405 | return E_NOEXS;
|
---|
| 406 |
|
---|
| 407 | /*
|
---|
| 408 | * ã¿ã¤ã ã¢ã¦ãããã§ãã¯ããã
|
---|
| 409 | */
|
---|
| 410 |
|
---|
| 411 | if (tmout == TMO_NBLK) { /* ãã³ããããã³ã°ã³ã¼ã« */
|
---|
| 412 |
|
---|
| 413 | /* é信端ç¹ãããã¯ããã*/
|
---|
| 414 | syscall(wai_sem(cep->semid_lock));
|
---|
| 415 |
|
---|
| 416 | if (cep->rcv_p_dstaddr != NULL)
|
---|
| 417 |
|
---|
| 418 | /* ãã³ããããã³ã°ã³ã¼ã«ã§ãã³ãã£ã³ã°ä¸ */
|
---|
| 419 | error = E_QOVR;
|
---|
| 420 |
|
---|
| 421 | else if (cep->rcv_tskid != TA_NULL)
|
---|
| 422 |
|
---|
| 423 | /* éãã³ããããã³ã°ã³ã¼ã«ã§ãã³ãã£ã³ã°ä¸ */
|
---|
| 424 | error = E_OBJ;
|
---|
| 425 | else {
|
---|
| 426 | cep->rcv_p_dstaddr = p_dstaddr;
|
---|
| 427 | cep->rcv_data = data;
|
---|
| 428 | cep->rcv_len = len;
|
---|
| 429 | error = E_WBLK;
|
---|
| 430 | }
|
---|
| 431 |
|
---|
| 432 | /* é信端ç¹ãããã¯ã解é¤ããã*/
|
---|
| 433 | syscall(sig_sem(cep->semid_lock));
|
---|
| 434 | return error;
|
---|
| 435 | }
|
---|
| 436 | else { /* éãã³ããããã³ã°ã³ã¼ã« */
|
---|
| 437 |
|
---|
| 438 | /* é信端ç¹ãããã¯ããã*/
|
---|
| 439 | syscall(wai_sem(cep->semid_lock));
|
---|
| 440 |
|
---|
| 441 | if (cep->rcv_p_dstaddr != NULL) {
|
---|
| 442 |
|
---|
| 443 | /* ãã³ããããã³ã°ã³ã¼ã«ã§ãã³ãã£ã³ã°ä¸ */
|
---|
| 444 | error = E_OBJ;
|
---|
| 445 |
|
---|
| 446 | /* é信端ç¹ãããã¯ã解é¤ããã*/
|
---|
| 447 | syscall(sig_sem(cep->semid_lock));
|
---|
| 448 | }
|
---|
| 449 | else if (cep->rcv_tskid != TA_NULL) {
|
---|
| 450 |
|
---|
| 451 | /* éãã³ããããã³ã°ã³ã¼ã«ã§ãã³ãã£ã³ã°ä¸ */
|
---|
| 452 | error = E_QOVR;
|
---|
| 453 |
|
---|
| 454 | /* é信端ç¹ãããã¯ã解é¤ããã*/
|
---|
| 455 | syscall(sig_sem(cep->semid_lock));
|
---|
| 456 | }
|
---|
| 457 | else {
|
---|
| 458 |
|
---|
| 459 | /* ç¾å¨ã®ã¿ã¹ã¯èå¥åãè¨é²ããã*/
|
---|
| 460 | get_tid(&(cep->rcv_tskid));
|
---|
| 461 |
|
---|
| 462 | /* é信端ç¹ãããã¯ã解é¤ããã*/
|
---|
| 463 | syscall(sig_sem(cep->semid_lock));
|
---|
| 464 |
|
---|
| 465 | /* å
|
---|
| 466 | ¥åãããã¾ã§å¾
|
---|
| 467 | ã¤ã*/
|
---|
| 468 | if (cep->cb_netbuf != NULL) {
|
---|
| 469 |
|
---|
| 470 | /*
|
---|
| 471 | * ããã«ããå ´åã¯ãã³ã¼ã«ããã¯é¢æ°ã®ä¸ãã
|
---|
| 472 | * udp_rcv_dat ãå¼ã³åºãã¦ãããã¨ã«ãªãã
|
---|
| 473 | * ãã§ã«å
|
---|
| 474 | ¥åæ¸ã¿ã§ããã
|
---|
| 475 | */
|
---|
| 476 | input = cep->cb_netbuf;
|
---|
| 477 | cep->cb_netbuf = NULL;
|
---|
| 478 | }
|
---|
| 479 | else if ((error = trcv_dtq(cep->rcvqid, (intptr_t*)&input, tmout)) != E_OK) {
|
---|
| 480 | cep->rcv_tskid = TA_NULL;
|
---|
| 481 | return error;
|
---|
| 482 | }
|
---|
| 483 |
|
---|
| 484 | /* p_dstaddr ãè¨å®ããã*/
|
---|
| 485 | uhoff = (uint_t)GET_UDP_HDR_OFFSET(input);
|
---|
| 486 | udph = GET_UDP_HDR(input, uhoff);
|
---|
| 487 | p_dstaddr->portno = ntohs(udph->sport);
|
---|
| 488 | IN_COPY_TO_HOST(&p_dstaddr->ipaddr, &GET_IP_HDR(input)->src);
|
---|
| 489 |
|
---|
| 490 | /* ãã¼ã¿ããããã¡ã«ç§»ãã*/
|
---|
| 491 | ulen = ntohs(udph->ulen);
|
---|
| 492 | if (ulen - UDP_HDR_SIZE > len)
|
---|
| 493 | error = E_BOVR;
|
---|
| 494 | else {
|
---|
| 495 | len = (int_t)(ulen - UDP_HDR_SIZE);
|
---|
| 496 | error = (ER_UINT)(ulen - UDP_HDR_SIZE);
|
---|
| 497 | }
|
---|
| 498 |
|
---|
| 499 | memcpy(data, GET_UDP_SDU(input, uhoff), (size_t)len);
|
---|
| 500 |
|
---|
| 501 | syscall(rel_net_buf(input));
|
---|
| 502 |
|
---|
| 503 | cep->rcv_tskid = TA_NULL;
|
---|
| 504 | }
|
---|
| 505 | return error;
|
---|
| 506 | }
|
---|
| 507 | }
|
---|
| 508 |
|
---|
| 509 | #endif /* of #ifdef __udp_rcv_dat */
|
---|
| 510 |
|
---|
| 511 | #endif /* of #ifdef UDP_CFG_NON_BLOCKING */
|
---|
| 512 |
|
---|
| 513 | #endif /* of #ifdef SUPPORT_UDP */
|
---|