Changeset 331 for EcnlProtoTool/trunk/asp3_dcre/tinet/netinet/udp_output.c
- Timestamp:
- Jan 21, 2018, 12:10:09 AM (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
EcnlProtoTool/trunk/asp3_dcre/tinet/netinet/udp_output.c
r321 r331 2 2 * TINET (TCP/IP Protocol Stack) 3 3 * 4 * Copyright (C) 2001-20 09by Dep. of Computer Science and Engineering4 * Copyright (C) 2001-2017 by Dep. of Computer Science and Engineering 5 5 * Tomakomai National College of Technology, JAPAN 6 6 * … … 73 73 #include <t_syslog.h> 74 74 #include "kernel_cfg.h" 75 #include "tinet_cfg.h" 75 76 76 77 #endif /* of #ifdef TARGET_KERNEL_ASP */ … … 81 82 #include <t_services.h> 82 83 #include "kernel_id.h" 84 #include "tinet_id.h" 83 85 84 86 #endif /* of #ifdef TARGET_KERNEL_JSP */ … … 92 94 #include <net/ethernet.h> 93 95 #include <net/net.h> 96 #include <net/net_endian.h> 94 97 #include <net/net_buf.h> 95 98 #include <net/net_count.h> 96 99 97 100 #include <netinet/in.h> 98 #include <netinet6/in6.h>99 101 #include <netinet/in_var.h> 100 102 #include <netinet/in_itron.h> … … 102 104 #include <netinet/ip_var.h> 103 105 #include <netinet/ip_icmp.h> 104 #include <netinet6/in6_var.h>105 #include <netinet/ip6.h>106 #include <netinet6/ip6_var.h>107 #include <netinet6/nd6.h>108 #include <netinet/icmp6.h>109 106 #include <netinet/udp.h> 110 107 #include <netinet/udp_var.h> … … 115 112 116 113 /* 117 * 関数 118 */ 119 120 static void udp_output (T_UDP_CEP *cep); 121 122 /* 123 * UDP 出力タスク 124 * ノンブロッキングコールを組み込んだとき使用する。 125 */ 126 127 static void 128 udp_output (T_UDP_CEP *cep) 129 { 130 T_NET_BUF *output; 131 T_UDP_HDR *udph; 132 ER_UINT error; 133 134 #ifdef UDP_CFG_OUT_CHECKSUM 135 uint16_t sum; 136 #endif /* of #ifdef UDP_CFG_OUT_CHECKSUM */ 137 138 /* IP データグラムを割り当てる。*/ 139 if ((error = IN_GET_DATAGRAM(&output, (uint_t)(UDP_HDR_SIZE + cep->snd_len), 0, 140 &cep->snd_p_dstaddr->ipaddr, 141 &cep->myaddr.ipaddr, 142 IPPROTO_UDP, IP_DEFTTL, 143 NBA_SEARCH_ASCENT, TMO_UDP_OUTPUT)) != E_OK) { 144 goto err_ret; 145 } 146 147 /* UDP ヘッダに情報を設定する。*/ 148 udph = GET_UDP_HDR(output, IF_IP_UDP_HDR_OFFSET); 149 udph->sport = htons(cep->myaddr.portno); 150 udph->dport = htons(cep->snd_p_dstaddr->portno); 151 udph->ulen = htons(UDP_HDR_SIZE + cep->snd_len); 152 udph->sum = 0; 153 154 /* データをコピーする。*/ 155 memcpy((void*)GET_UDP_SDU(output, IF_IP_UDP_HDR_OFFSET), 156 cep->snd_data, (size_t)cep->snd_len); 157 158 #ifdef UDP_CFG_OUT_CHECKSUM 159 160 sum = IN_CKSUM(output, IPPROTO_UDP, IF_IP_UDP_HDR_OFFSET, 161 (uint_t)(UDP_HDR_SIZE + cep->snd_len)); 162 163 /* 計算したチェックサムの値が 0 なら 0xffff を入れる。*/ 164 if (sum == 0) 165 sum = UINT_C(0xffff); 166 udph->sum = sum; 167 168 #endif/* of #ifdef UDP_CFG_OUT_CHECKSUM */ 169 170 /* ネットワークバッファ長を調整する。*/ 171 output->len = (uint16_t)(IF_IP_UDP_HDR_SIZE + cep->snd_len); 172 173 /* ネットワーク層 (IP) の出力関数を呼び出す。*/ 174 if ((error = IP_OUTPUT(output, TMO_UDP_OUTPUT)) != E_OK) 175 goto err_ret; 176 177 178 NET_COUNT_MIB(udp_stats.udpOutDatagrams, 1); 179 180 if (IS_PTR_DEFINED(cep->callback)) { 181 182 if (error == E_OK) 183 error = cep->snd_len; 184 185 #ifdef TCP_CFG_NON_BLOCKING_COMPAT14 186 187 (*cep->callback)(GET_UDP_CEPID(cep), TFN_UDP_SND_DAT, (void*)error); 188 189 #else /* of #ifdef TCP_CFG_NON_BLOCKING_COMPAT14 */ 190 191 (*cep->callback)(GET_UDP_CEPID(cep), TFN_UDP_SND_DAT, (void*)&error); 192 193 #endif /* of #ifdef TCP_CFG_NON_BLOCKING_COMPAT14 */ 194 195 } 196 else 197 syslog(LOG_WARNING, "[UDP] no call back, CEP: %d.", GET_UDP_CEPID(cep)); 198 cep->snd_p_dstaddr = NULL; 199 return; 200 201 err_ret: 202 NET_COUNT_UDP(net_count_udp.out_err_packets, 1); 203 if (IS_PTR_DEFINED(cep->callback)) { 204 205 #ifdef TCP_CFG_NON_BLOCKING_COMPAT14 206 207 (*cep->callback)(GET_UDP_CEPID(cep), TFN_UDP_SND_DAT, (void*)E_NOMEM); 208 209 #else /* of #ifdef TCP_CFG_NON_BLOCKING_COMPAT14 */ 210 211 error = E_NOMEM; 212 (*cep->callback)(GET_UDP_CEPID(cep), TFN_UDP_SND_DAT, (void*)&error); 213 214 #endif /* of #ifdef TCP_CFG_NON_BLOCKING_COMPAT14 */ 215 216 } 217 else 218 syslog(LOG_WARNING, "[UDP] no call back, CEP: %d.", GET_UDP_CEPID(cep)); 219 cep->snd_p_dstaddr = NULL; 220 return; 221 } 114 * IPv6 と IPv4 で引数が異なる関数のコンパイル 115 */ 116 117 #undef IN_GET_DATAGRAM 118 119 #if defined(_IP6_CFG) 120 121 #define UDP_OUTPUT udp6_output 122 #define GET_UDP_CEPID GET_UDP6_CEPID 123 #define T_UDP_CEP T_UDP6_CEP 124 #define API_PROTO API_PROTO_IPV6 125 126 #if defined(_IP4_CFG) 127 #define IN_GET_DATAGRAM inn_get_datagram 128 #else 129 #define IN_GET_DATAGRAM in6_get_datagram 130 #endif 131 132 #include <netinet/udpn_output.c> 133 134 #undef UDP_OUTPUT 135 #undef GET_UDP_CEPID 136 #undef T_UDP_CEP 137 #undef API_PROTO 138 #undef IN_GET_DATAGRAM 139 140 #endif /* of #if defined(_IP6_CFG) */ 141 142 #if defined(_IP4_CFG) && TNUM_UDP4_CEPID > 0 143 144 #define UDP_OUTPUT udp4_output 145 #define GET_UDP_CEPID GET_UDP4_CEPID 146 #define T_UDP_CEP T_UDP4_CEP 147 #define API_PROTO API_PROTO_IPV4 148 149 #define IN_GET_DATAGRAM in4_get_datagram 150 151 #include <netinet/udpn_output.c> 152 153 #endif /* of #if defined(_IP4_CFG) && TNUM_UDP4_CEPID > 0 */ 222 154 223 155 /* … … 236 168 237 169 238 #if defined( SUPPORT_INET6) && !defined(SUPPORT_TCP)170 #if defined(_IP6_CFG) && !defined(SUPPORT_TCP) 239 171 240 172 /* IPv6 のステートレス・アドレス自動設定を実行する。*/ 241 173 in6_if_up(IF_GET_IFNET()); 242 174 243 #endif /* of #if defined( SUPPORT_INET6) && !defined(SUPPORT_TCP) */175 #endif /* of #if defined(_IP6_CFG) && !defined(SUPPORT_TCP) */ 244 176 245 177 while (true) { … … 248 180 syscall(wai_sem(SEM_UDP_POST_OUTPUT)); 249 181 250 for (ix = tmax_udp_ccepid; ix -- > 0; ) { 251 252 if (udp_cep[ix].flags & UDP_CEP_FLG_POST_OUTPUT) { 253 udp_cep[ix].flags &= ~UDP_CEP_FLG_POST_OUTPUT; 254 udp_output(&udp_cep[ix]); 182 #if defined(_IP6_CFG) && TNUM_UDP6_CEPID > 0 183 184 for (ix = tmax_udp6_cepid; ix -- > 0; ) { 185 186 if (udp6_cep[ix].flags & UDP_CEP_FLG_POST_OUTPUT) { 187 udp6_cep[ix].flags &= ~UDP_CEP_FLG_POST_OUTPUT; 188 udp6_output(&udp6_cep[ix]); 255 189 } 256 190 } 191 192 #endif /* of #if defined(_IP6_CFG) && TNUM_UDP6_CEPID > 0 */ 193 194 #if defined(_IP4_CFG) && TNUM_UDP4_CEPID > 0 195 196 for (ix = tmax_udp4_cepid; ix -- > 0; ) { 197 198 if (udp4_cep[ix].flags & UDP_CEP_FLG_POST_OUTPUT) { 199 udp4_cep[ix].flags &= ~UDP_CEP_FLG_POST_OUTPUT; 200 udp4_output(&udp4_cep[ix]); 201 } 202 } 203 204 #endif /* of #if defined(_IP4_CFG) && TNUM_UDP4_CEPID > 0 */ 205 257 206 } 258 207 }
Note:
See TracChangeset
for help on using the changeset viewer.