[270] | 1 | /*
|
---|
| 2 | * TINET (TCP/IP Protocol Stack)
|
---|
| 3 | *
|
---|
[331] | 4 | * Copyright (C) 2001-2017 by Dep. of Computer Science and Engineering
|
---|
[270] | 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, 1989, 1993
|
---|
| 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 | * @(#)udp_var.h 8.1 (Berkeley) 6/10/93
|
---|
| 67 | * $FreeBSD: src/sys/netinet/udp_var.h,v 1.16.2.2 1999/08/29 16:29:59 peter Exp $
|
---|
| 68 | */
|
---|
| 69 |
|
---|
| 70 | #ifndef _UDP_VAR_H_
|
---|
| 71 | #define _UDP_VAR_H_
|
---|
| 72 |
|
---|
| 73 | /*
|
---|
| 74 | * UDP ヘッダ・ペイロードアクセスマクロ
|
---|
| 75 | */
|
---|
| 76 |
|
---|
| 77 | #define GET_UDP_HDR(nbuf,uhoff) ((T_UDP_HDR*)((uint8_t*)((nbuf)->buf) + uhoff))
|
---|
[331] | 78 | #define GET_UDP_HDR_OFFSET(nbuf) (GET_IF_IP_HDR_SIZE(nbuf))
|
---|
[270] | 79 | #define GET_UDP_SDU(nbuf,uhoff) ((uint8_t*)((nbuf)->buf) + uhoff+ UDP_HDR_SIZE)
|
---|
| 80 |
|
---|
[331] | 81 | #define IF_IP_UDP_HDR_SIZE(nbuf) (IF_IP_HDR_SIZE(nbuf) + UDP_HDR_SIZE)
|
---|
| 82 | #define IF_IP_UDP_HDR_OFFSET(nbuf) (IF_IP_HDR_SIZE(nbuf))
|
---|
[270] | 83 |
|
---|
| 84 | /*
|
---|
| 85 | * TINET 1.1 との互換性のための定義
|
---|
| 86 | */
|
---|
| 87 |
|
---|
[331] | 88 | #if defined(_IP4_CFG)
|
---|
[270] | 89 |
|
---|
| 90 | #define IP4_UDP_HDR_SIZE IP_UDP_HDR_SIZE
|
---|
| 91 | #define IF_IP4_UDP_HDR_SIZE IF_IP_UDP_HDR_SIZE
|
---|
| 92 | #define GET_IP4_UDP_HDR_SIZE(nbuf) GET_IP_UDP_HDR_SIZE(nbuf)
|
---|
| 93 | #define GET_IF_IP4_UDP_HDR_SIZE(nbuf) GET_IF_IP_UDP_HDR_SIZE(nbuf)
|
---|
| 94 |
|
---|
[331] | 95 | #endif /* of #if defined(_IP4_CFG) */
|
---|
[270] | 96 |
|
---|
| 97 | /*
|
---|
| 98 | * コールバック関数の定義
|
---|
| 99 | */
|
---|
| 100 |
|
---|
| 101 | typedef ER (*t_udp_callback)(ID cepid, FN fncd, void *p_parblk);
|
---|
| 102 |
|
---|
[429] | 103 | typedef struct t_udp_rcv_dat_para {
|
---|
| 104 | uint_t len;
|
---|
| 105 | T_NET_BUF *input;
|
---|
| 106 | uint_t off;
|
---|
| 107 | union {
|
---|
| 108 | T_IPV4EP rep4;
|
---|
| 109 | T_IPV6EP rep6;
|
---|
| 110 | };
|
---|
| 111 | } T_UDP_RCV_DAT_PARA;
|
---|
| 112 |
|
---|
[270] | 113 | /*
|
---|
| 114 | * UDP 通信端点
|
---|
| 115 | */
|
---|
| 116 |
|
---|
[331] | 117 | /* IPv6 用 UDP 通信端点 */
|
---|
[270] | 118 |
|
---|
[331] | 119 | typedef struct t_udp6_cep {
|
---|
[270] | 120 |
|
---|
| 121 | /*
|
---|
| 122 | * ITRON TCP/IP API、TCP 通信端点と同じメンバ
|
---|
| 123 | */
|
---|
| 124 | ATR cepatr; /* UDP 通信端点属性 */
|
---|
[331] | 125 | T_IPV6EP myaddr; /* 自分のアドレス */
|
---|
[270] | 126 | t_udp_callback callback; /* コールバック関数 */
|
---|
| 127 |
|
---|
| 128 | /*
|
---|
| 129 | * TINET 独自のメンバ
|
---|
| 130 | */
|
---|
| 131 | uint16_t flags; /* 通信端点フラグ */
|
---|
| 132 | ID semid_lock; /* 通信端点ロック */
|
---|
| 133 | ID snd_tskid; /* 送信タスク識別子 */
|
---|
| 134 | ID rcv_tskid; /* 受信タスク識別子 */
|
---|
| 135 | ID rcvqid; /* 非コールバック用受信キュー識別子*/
|
---|
| 136 | T_NET_BUF *cb_netbuf; /* コールバック用受信ネットワークバッファ*/
|
---|
| 137 |
|
---|
| 138 | #ifdef UDP_CFG_NON_BLOCKING
|
---|
| 139 |
|
---|
[331] | 140 | T_IPV6EP *snd_p_dstaddr; /* 送信相手のアドレスへのポインタ*/
|
---|
| 141 | T_IPV6EP *rcv_p_dstaddr; /* 受信相手のアドレスへのポインタ*/
|
---|
[270] | 142 | void *snd_data; /* 送信データ領域の先頭アドレス */
|
---|
| 143 | int_t snd_len; /* 送信データ領域の長さ */
|
---|
| 144 | void *rcv_data; /* 受信データ領域の先頭アドレス */
|
---|
| 145 | int_t rcv_len; /* 受信データ領域の長さ */
|
---|
| 146 |
|
---|
| 147 | #endif /* of #ifdef UDP_CFG_NON_BLOCKING */
|
---|
| 148 |
|
---|
| 149 | #ifdef UDP_CFG_EXTENTIONS
|
---|
| 150 | ER error; /* 待ち中に発生したエラー */
|
---|
| 151 | #endif
|
---|
| 152 |
|
---|
[429] | 153 | #ifdef SUPPORT_IGMP
|
---|
| 154 | bool_t igmp_loopback;
|
---|
| 155 | uint8_t igmp_ttl;
|
---|
| 156 | T_IN4_ADDR igmp_mcaddr; /* */
|
---|
| 157 | #endif
|
---|
| 158 |
|
---|
[331] | 159 | } T_UDP6_CEP;
|
---|
[270] | 160 |
|
---|
[331] | 161 | /* IPv4 用 UDP 通信端点 */
|
---|
[270] | 162 |
|
---|
[331] | 163 | typedef struct t_udp4_cep {
|
---|
[270] | 164 |
|
---|
| 165 | /*
|
---|
| 166 | * ITRON TCP/IP API、TCP 通信端点と同じメンバ
|
---|
| 167 | */
|
---|
| 168 | ATR cepatr; /* UDP 通信端点属性 */
|
---|
[331] | 169 | T_IPV4EP myaddr; /* 自分のアドレス */
|
---|
[270] | 170 | t_udp_callback callback; /* コールバック関数 */
|
---|
| 171 |
|
---|
| 172 | /*
|
---|
| 173 | * TINET 独自のメンバ
|
---|
| 174 | */
|
---|
| 175 | uint16_t flags; /* 通信端点フラグ */
|
---|
| 176 | ID semid_lock; /* 通信端点ロック */
|
---|
| 177 | ID snd_tskid; /* 送信タスク識別子 */
|
---|
| 178 | ID rcv_tskid; /* 受信タスク識別子 */
|
---|
| 179 | ID rcvqid; /* 非コールバック用受信キュー識別子*/
|
---|
| 180 | T_NET_BUF *cb_netbuf; /* コールバック用受信ネットワークバッファ*/
|
---|
| 181 |
|
---|
| 182 | #ifdef UDP_CFG_NON_BLOCKING
|
---|
| 183 |
|
---|
[331] | 184 | T_IPV4EP *snd_p_dstaddr; /* 送信相手のアドレスへのポインタ*/
|
---|
| 185 | T_IPV4EP *rcv_p_dstaddr; /* 受信相手のアドレスへのポインタ*/
|
---|
[270] | 186 | void *snd_data; /* 送信データ領域の先頭アドレス */
|
---|
| 187 | int_t snd_len; /* 送信データ領域の長さ */
|
---|
| 188 | void *rcv_data; /* 受信データ領域の先頭アドレス */
|
---|
| 189 | int_t rcv_len; /* 受信データ領域の長さ */
|
---|
| 190 |
|
---|
| 191 | #endif /* of #ifdef UDP_CFG_NON_BLOCKING */
|
---|
| 192 |
|
---|
| 193 | #ifdef UDP_CFG_EXTENTIONS
|
---|
| 194 | ER error; /* 待ち中に発生したエラー */
|
---|
| 195 | #endif
|
---|
[429] | 196 |
|
---|
[331] | 197 | #ifdef SUPPORT_IGMP
|
---|
| 198 | bool_t igmp_loopback;
|
---|
| 199 | uint8_t igmp_ttl;
|
---|
| 200 | T_IN4_ADDR igmp_mcaddr; /* */
|
---|
| 201 | #endif
|
---|
[429] | 202 |
|
---|
[331] | 203 | } T_UDP4_CEP;
|
---|
[270] | 204 |
|
---|
[331] | 205 | #if defined(_IP6_CFG)
|
---|
[270] | 206 |
|
---|
| 207 | #define T_UDP_CEP T_UDP6_CEP
|
---|
| 208 |
|
---|
[331] | 209 | #else /* of #if defined(_IP6_CFG) */
|
---|
| 210 |
|
---|
| 211 | #if defined(_IP4_CFG)
|
---|
| 212 |
|
---|
| 213 | #define T_UDP_CEP T_UDP4_CEP
|
---|
| 214 |
|
---|
| 215 | #endif /* of #if defined(_IP4_CFG) */
|
---|
| 216 |
|
---|
| 217 | #endif /* of #if defined(_IP6_CFG) */
|
---|
| 218 |
|
---|
[270] | 219 | /*
|
---|
| 220 | * UDP 通信端点フラグ
|
---|
| 221 | */
|
---|
| 222 |
|
---|
| 223 | #define UDP_CEP_FLG_POST_OUTPUT UINT_C(0x0200) /* 送信を開始する。 */
|
---|
| 224 | #define UDP_CEP_FLG_DYNAMIC UINT_C(0x0400) /* 動的生成・削除可能通信端点。 */
|
---|
| 225 | #define UDP_CEP_FLG_VALID UINT_C(0x0800) /* 生成済みで有効な通信端点。 */
|
---|
| 226 |
|
---|
| 227 | /*
|
---|
| 228 | * オブジェクト ID の最小値の定義
|
---|
| 229 | */
|
---|
| 230 |
|
---|
[331] | 231 | #define TMIN_UDP_CEPID 1 /* UDP 通信端点 ID の最小値 */
|
---|
| 232 | #define TMIN_UDP6_CEPID 1 /* UDP/IPv6 通信端点 ID の最小値 */
|
---|
| 233 | #define TMIN_UDP4_CEPID (TNUM_UDP6_CEPID+1) /* UDP/IPv4 通信端点 ID の最小値 */
|
---|
[270] | 234 |
|
---|
| 235 | /*
|
---|
| 236 | * SNMP の 管理情報ベース (MIB)
|
---|
| 237 | */
|
---|
| 238 |
|
---|
| 239 | typedef struct t_udp_stats {
|
---|
| 240 | uint32_t udpInDatagrams;
|
---|
| 241 | uint32_t udpNoPorts;
|
---|
| 242 | uint32_t udpInErrors;
|
---|
| 243 | uint32_t udpOutDatagrams;
|
---|
| 244 | } T_UDP_STATS;
|
---|
| 245 |
|
---|
| 246 | /*
|
---|
| 247 | * 関数シミュレーションマクロ
|
---|
| 248 | */
|
---|
| 249 |
|
---|
[331] | 250 | #define VALID_UDP6_CEPID(id) (TMIN_UDP6_CEPID<=(id)&&(id)<=tmax_udp6_cepid)
|
---|
| 251 | #define VALID_UDP4_CEPID(id) (TMIN_UDP4_CEPID<=(id)&&(id)<=tmax_udp4_cepid)
|
---|
[270] | 252 |
|
---|
[331] | 253 | #define INDEX_UDP6_CEP(id) ((id)-TMIN_UDP6_CEPID)
|
---|
| 254 | #define INDEX_UDP4_CEP(id) ((id)-TMIN_UDP4_CEPID)
|
---|
[270] | 255 |
|
---|
[331] | 256 | #define GET_UDP6_CEP(id) (&(udp6_cep[INDEX_UDP6_CEP(id)]))
|
---|
| 257 | #define GET_UDP4_CEP(id) (&(udp4_cep[INDEX_UDP4_CEP(id)]))
|
---|
[270] | 258 |
|
---|
[331] | 259 | #define GET_UDP6_CEPID(cep) ((ID)(((cep)-udp6_cep)+TMIN_UDP6_CEPID))
|
---|
| 260 | #define GET_UDP4_CEPID(cep) ((ID)(((cep)-udp4_cep)+TMIN_UDP4_CEPID))
|
---|
[270] | 261 |
|
---|
| 262 | #define VALID_TFN_UDP_CAN(t) ((t)==TFN_UDP_SND_DAT||(t)==TFN_UDP_RCV_DAT||\
|
---|
| 263 | (t)==TFN_UDP_ALL)
|
---|
| 264 |
|
---|
| 265 | #define VALID_UDP_CEP(cep) (((cep)->flags&UDP_CEP_FLG_VALID)!=0)
|
---|
| 266 | #define DYNAMIC_UDP_CEP(cep) (((cep)->flags&UDP_CEP_FLG_DYNAMIC)!=0)
|
---|
| 267 |
|
---|
| 268 | /*
|
---|
| 269 | * 全域変数
|
---|
| 270 | */
|
---|
| 271 |
|
---|
[331] | 272 | extern T_UDP_STATS udp_stats;
|
---|
[270] | 273 |
|
---|
[331] | 274 | /* UDP 通信端点 */
|
---|
[270] | 275 |
|
---|
[331] | 276 | extern T_UDP6_CEP udp6_cep[];
|
---|
| 277 | extern T_UDP4_CEP udp4_cep[];
|
---|
[270] | 278 |
|
---|
[331] | 279 | #if defined(SUPPORT_INET6)
|
---|
| 280 | #define udp_cep udp6_cep
|
---|
| 281 | #elif defined(SUPPORT_INET4)
|
---|
| 282 | #define udp_cep udp4_cep
|
---|
| 283 | #endif
|
---|
[270] | 284 |
|
---|
[331] | 285 | extern const ID tmax_udp_cepid;
|
---|
| 286 |
|
---|
| 287 | #if defined(SUPPORT_INET6) && defined(SUPPORT_INET4)
|
---|
| 288 | extern const ID tmax_udp6_cepid;
|
---|
| 289 | extern const ID tmax_udp4_cepid;
|
---|
| 290 | #else
|
---|
| 291 | #define tmax_udp6_cepid tmax_udp_cepid
|
---|
| 292 | #define tmax_udp4_cepid tmax_udp_cepid
|
---|
| 293 | #endif
|
---|
| 294 |
|
---|
[270] | 295 | /*
|
---|
| 296 | * TINET 1.3 との互換性のための定義
|
---|
| 297 | */
|
---|
| 298 |
|
---|
| 299 | #define TMIN_UDP_CCEPID TMIN_UDP_CEPID
|
---|
| 300 | #define TNUM_UDP_CCEPID TNUM_UDP_CEPID
|
---|
| 301 |
|
---|
| 302 | /*
|
---|
| 303 | * 関数
|
---|
| 304 | */
|
---|
| 305 |
|
---|
[331] | 306 | /* IPv6 */
|
---|
[270] | 307 |
|
---|
[331] | 308 | extern uint_t udp6_input (T_NET_BUF **inputp, uint_t *offp, uint_t *nextp);
|
---|
| 309 | extern ER_UINT udp6_send_data (T_UDP6_CEP *cep, T_IPV6EP *p_dstaddr,
|
---|
| 310 | void *data, int_t len, TMO tmout);
|
---|
| 311 | extern ER udp6_can_snd (T_UDP6_CEP *cep, ER error);
|
---|
| 312 | extern ER udp6_can_rcv (T_UDP6_CEP *cep, ER error);
|
---|
| 313 | extern ER udp6_alloc_auto_port (T_UDP6_CEP *cep);
|
---|
| 314 | extern ER udp6_alloc_port (T_UDP6_CEP *cep, uint16_t portno);
|
---|
| 315 | extern T_UDP6_CEP*udp6_find_cep (T_NET_BUF *input, uint_t off);
|
---|
| 316 | extern void udp6_notify (T_NET_BUF *input, ER error);
|
---|
| 317 | extern void udp6_input_select (T_UDP6_CEP *cep, T_NET_BUF *input, uint_t off);
|
---|
| 318 |
|
---|
| 319 | /* IPv4 */
|
---|
| 320 |
|
---|
| 321 | extern uint_t udp4_input (T_NET_BUF **inputp, uint_t *offp, uint_t *nextp);
|
---|
| 322 | extern ER_UINT udp4_send_data (T_UDP4_CEP *cep, T_IPV4EP *p_dstaddr,
|
---|
| 323 | void *data, int_t len, TMO tmout);
|
---|
| 324 | extern ER udp4_can_snd (T_UDP4_CEP *cep, ER error);
|
---|
| 325 | extern ER udp4_can_rcv (T_UDP4_CEP *cep, ER error);
|
---|
| 326 | extern ER udp4_alloc_auto_port (T_UDP4_CEP *cep);
|
---|
| 327 | extern ER udp4_alloc_port (T_UDP4_CEP *cep, uint16_t portno);
|
---|
| 328 | extern T_UDP4_CEP*udp4_find_cep (T_NET_BUF *input, uint_t off);
|
---|
| 329 | extern void udp4_notify (T_NET_BUF *input, ER error);
|
---|
| 330 | extern void udp4_input_select (T_UDP4_CEP *cep, T_NET_BUF *input, uint_t off);
|
---|
| 331 |
|
---|
[270] | 332 | /* ノンブロッキングコールを行う場合に組み込むタスク */
|
---|
| 333 |
|
---|
| 334 | extern void udp_output_task(intptr_t exinf);
|
---|
| 335 |
|
---|
| 336 | #endif /* of #ifndef _UDP_VAR_H_ */
|
---|