source: asp3_tinet_ecnl_arm/trunk/asp3_dcre/tinet/netinet/udpn_input.c@ 352

Last change on this file since 352 was 352, checked in by coas-nagasima, 6 years ago

arm向けASP3版ECNLを追加

  • Property svn:eol-style set to native
  • Property svn:mime-type set to text/x-csrc;charset=UTF-8
File size: 8.5 KB
Line 
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 * 上記著作権者は,以下の (1)~(4) の条件か,Free Software Foundation
8 * によって公表されている GNU General Public License の Version 2 に記
9 * 述されている条件を満たす場合に限り,本ソフトウェア(本ソフトウェア
10 * を改変したものを含む.以下同じ)を使用・複製・改変・再配布(以下,
11 * 利用と呼ぶ)することを無償で許諾する.
12 * (1) 本ソフトウェアをソースコードの形で利用する場合には,上記の著作
13 * 権表示,この利用条件および下記の無保証規定が,そのままの形でソー
14 * スコード中に含まれていること.
15 * (2) 本ソフトウェアを,ライブラリ形式など,他のソフトウェア開発に使
16 * 用できる形で再配布する場合には,再配布に伴うドキュメント(利用
17 * 者マニュアルなど)に,上記の著作権表示,この利用条件および下記
18 * の無保証規定を掲載すること.
19 * (3) 本ソフトウェアを,機器に組み込むなど,他のソフトウェア開発に使
20 * 用できない形で再配布する場合には,次の条件を満たすこと.
21 * (a) 再配布に伴うドキュメント(利用者マニュアルなど)に,上記の著
22 * 作権表示,この利用条件および下記の無保証規定を掲載すること.
23 * (4) 本ソフトウェアの利用により直接的または間接的に生じるいかなる損
24 * 害からも,上記著作権者およびTOPPERSプロジェクトを免責すること.
25 *
26 * 本ソフトウェアは,無保証で提供されているものである.上記著作権者お
27 * よびTOPPERSプロジェクトは,本ソフトウェアに関して,その適用可能性も
28 * 含めて,いかなる保証も行わない.また,本ソフトウェアの利用により直
29 * 接的または間接的に生じたいかなる損害に関しても,その責任を負わない.
30 *
31 * @(#) $Id$
32 */
33
34/*
35 * Copyright (c) 1982, 1986, 1988, 1990, 1993, 1995
36 * The Regents of the University of California. All rights reserved.
37 *
38 * Redistribution and use in source and binary forms, with or without
39 * modification, are permitted provided that the following conditions
40 * are met:
41 * 1. Redistributions of source code must retain the above copyright
42 * notice, this list of conditions and the following disclaimer.
43 * 2. Redistributions in binary form must reproduce the above copyright
44 * notice, this list of conditions and the following disclaimer in the
45 * documentation and/or other materials provided with the distribution.
46 * 3. All advertising materials mentioning features or use of this software
47 * must display the following acknowledgement:
48 * This product includes software developed by the University of
49 * California, Berkeley and its contributors.
50 * 4. Neither the name of the University nor the names of its contributors
51 * may be used to endorse or promote products derived from this software
52 * without specific prior written permission.
53 *
54 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
55 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
56 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
57 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
58 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
59 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
60 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
61 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
62 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
63 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
64 * SUCH DAMAGE.
65 */
66
67#if (API_PROTO == API_PROTO_IPV6) || (TNUM_UDP4_CEPID > 0)
68
69/*
70 * udp_input_select -- UDP の入力処理の選択
71 */
72
73void
74UDP_INPUT_SELECT (T_UDP_CEP *cep, T_NET_BUF *input, uint_t off)
75{
76 T_UDP_HDR *udph;
77 uint_t len;
78
79 udph = (T_UDP_HDR *)(input->buf + off);
80 len = (uint_t)(ntohs(udph->ulen) - UDP_HDR_SIZE);
81
82 if (cep->rcv_tskid != TA_NULL) { /* 非ノンブロッキングコールでペンディング中 */
83 if (psnd_dtq(cep->rcvqid, (intptr_t)input) != E_OK) {
84 NET_COUNT_UDP(net_count_udp.in_err_packets, 1);
85 NET_COUNT_MIB(udp_stats.udpInErrors, 1);
86 syscall(rel_net_buf(input));
87 }
88 }
89
90#ifdef UDP_CFG_NON_BLOCKING
91
92 else if (cep->rcv_p_dstaddr != NULL) { /* ノンブロッキングコールでペンディング中 */
93
94 /* p_dstaddr を設定する。*/
95 cep->rcv_p_dstaddr->portno = ntohs(udph->sport);
96 IN_COPY_TO_HOST(&cep->rcv_p_dstaddr->ipaddr, input);
97
98 /* データをバッファに移す。*/
99 memcpy(cep->rcv_data, GET_UDP_SDU(input, off),
100 (size_t)(len < cep->rcv_len ? len : cep->rcv_len));
101 syscall(rel_net_buf(input));
102
103 if (IS_PTR_DEFINED(cep->callback))
104
105#ifdef TCP_CFG_NON_BLOCKING_COMPAT14
106 (*cep->callback)(GET_UDP_CEPID(cep), TFN_UDP_RCV_DAT, (void*)(uint32_t)len);
107#else
108 (*cep->callback)(GET_UDP_CEPID(cep), TFN_UDP_RCV_DAT, (void*)&len);
109#endif
110 else
111 syslog(LOG_WARNING, "[UDP] no call back, CEP: %d.", GET_UDP_CEPID(cep));
112 cep->rcv_p_dstaddr = NULL;
113 }
114
115#endif/* of #ifdef UDP_CFG_NON_BLOCKING */
116
117 else if (IS_PTR_DEFINED(cep->callback)) {
118
119 /* コールバック関数を呼び出す。*/
120 cep->cb_netbuf = input;
121
122#ifdef TCP_CFG_NON_BLOCKING_COMPAT14
123 (*cep->callback)(GET_UDP_CEPID(cep), TEV_UDP_RCV_DAT, (void*)(uint32_t)len);
124#else
125 (*cep->callback)(GET_UDP_CEPID(cep), TEV_UDP_RCV_DAT, (void*)&len);
126#endif
127 /*
128 * ネットワークバッファがそのままであれば、コールバック関数内で
129 * データを読み出さなかったことになるので、捨てる。
130 */
131 if (cep->cb_netbuf != NULL)
132 syscall(rel_net_buf(cep->cb_netbuf));
133 }
134 else {
135 NET_COUNT_UDP(net_count_udp.in_err_packets, 1);
136 NET_COUNT_MIB(udp_stats.udpInErrors, 1);
137 syscall(rel_net_buf(input));
138 }
139
140 }
141
142#endif /* of #if (API_PROTO == API_PROTO_IPV6) || (TNUM_UDP4_CEPID > 0) */
143
144/*
145 * udp_input -- UDP の入力関数
146 */
147
148uint_t
149UDP_INPUT (T_NET_BUF **inputp, uint_t *offp, uint_t *nextp)
150{
151 T_NET_BUF *input = *inputp;
152 T_UDP_CEP *cep;
153 T_UDP_HDR *udph;
154 uint_t hlen, ulen;
155
156#if defined(_IP6_CFG) && defined(_IP4_CFG) && API_PROTO == API_PROTO_IPV4
157 T_UDP6_CEP *cep6;
158#endif
159
160 hlen = (uint_t)GET_IF_IP_HDR_SIZE(input);
161
162 NET_COUNT_UDP(net_count_udp.in_octets, input->len - hlen);
163 NET_COUNT_UDP(net_count_udp.in_packets, 1);
164 NET_COUNT_MIB(udp_stats.udpInDatagrams, 1);
165
166 /* ヘッダ長をチェックする。*/
167 if (input->len < hlen + UDP_HDR_SIZE)
168 goto buf_rel;
169
170 udph = (T_UDP_HDR *)(input->buf + *offp);
171
172 /* データグラム長をチェックする */
173 ulen = ntohs(udph->ulen);
174 if (ulen != input->len - hlen)
175 goto buf_rel;
176
177 /* 宛先ポートが 0 のデータグラムは破棄する。RFC768 */
178 if (udph->dport == 0)
179 goto buf_rel;
180
181#ifdef UDP_CFG_IN_CHECKSUM
182
183 /* チェックサムをチェックする */
184 if (udph->sum && IN_CKSUM(input, IPPROTO_UDP, *offp, ulen) != 0)
185 goto buf_rel;
186
187#endif /* of #ifdef UDP_CFG_IN_CHECKSUM */
188
189#if defined(_IP6_CFG) && defined(_IP4_CFG) && API_PROTO == API_PROTO_IPV4
190
191#if TNUM_UDP4_CEPID > 0
192
193 /* UDP 通信端点を得る。*/
194 cep = udp4_find_cep(input, *offp);
195
196 if (cep != NULL)
197 udp4_input_select(cep, input, *offp);
198 else if ((cep6 = udp6_find_cep(input, *offp)) != NULL)
199 udp6_input_select(cep6, input, *offp);
200 else
201 udp4_reply_no_port(input, *offp);
202
203 return IPPROTO_DONE;
204
205#else /* of #if TNUM_UDP4_CEPID > 0 */
206
207 cep = 0; /* warning 回避用のダミー */
208 if ((cep6 = udp6_find_cep(input, *offp)) != NULL)
209 udp6_input_select(cep6, input, *offp);
210 else
211 udp4_reply_no_port(input, *offp);
212
213 return IPPROTO_DONE;
214
215#endif /* of #if TNUM_UDP4_CEPID > 0 */
216
217#else /* of #if defined(_IP6_CFG) && defined(_IP4_CFG) && API_PROTO == API_PROTO_IPV4 */
218
219 /* UDP 通信端点を得る。*/
220 cep = UDP_FIND_CEP(input, *offp);
221
222 if (cep != NULL)
223 UDP_INPUT_SELECT(cep, input, *offp);
224 else
225 UDP_REPLY_NO_PORT(input, *offp);
226
227 return IPPROTO_DONE;
228
229#endif /* of #if defined(_IP6_CFG) && defined(_IP4_CFG) && API_PROTO == API_PROTO_IPV4 */
230
231buf_rel:
232 NET_COUNT_UDP(net_count_udp.in_err_packets, 1);
233 NET_COUNT_MIB(udp_stats.udpInErrors, 1);
234 syscall(rel_net_buf(input));
235 return IPPROTO_DONE;
236 }
Note: See TracBrowser for help on using the repository browser.