[270] | 1 | /*
|
---|
| 2 | * TINET (TCP/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_discard_cli.c 270 2017-02-09 04:03:47Z coas-nagasima $
|
---|
| 44 | */
|
---|
| 45 |
|
---|
| 46 | /*
|
---|
| 47 | * UDP DISCARD ã¯ã©ã¤ã¢ã³ã
|
---|
| 48 | */
|
---|
| 49 |
|
---|
| 50 | #include <stdlib.h>
|
---|
| 51 | #include <string.h>
|
---|
| 52 |
|
---|
| 53 | #ifdef TARGET_KERNEL_ASP
|
---|
| 54 |
|
---|
| 55 | #include <kernel.h>
|
---|
| 56 | #include <sil.h>
|
---|
| 57 | #include <t_syslog.h>
|
---|
| 58 | #include "kernel_cfg.h"
|
---|
| 59 |
|
---|
| 60 | #endif /* of #ifdef TARGET_KERNEL_ASP */
|
---|
| 61 |
|
---|
| 62 | #ifdef TARGET_KERNEL_JSP
|
---|
| 63 |
|
---|
| 64 | #include <t_services.h>
|
---|
| 65 | #include "kernel_id.h"
|
---|
| 66 | #include "tinet_id.h"
|
---|
| 67 |
|
---|
| 68 | #endif /* of #ifdef TARGET_KERNEL_JSP */
|
---|
| 69 |
|
---|
| 70 | #include <tinet_defs.h>
|
---|
| 71 | #include <tinet_config.h>
|
---|
| 72 |
|
---|
| 73 | #include <net/if.h>
|
---|
| 74 | #include <net/if_ppp.h>
|
---|
| 75 | #include <net/if_loop.h>
|
---|
| 76 | #include <net/ethernet.h>
|
---|
| 77 | #include <net/net.h>
|
---|
| 78 | #include <net/net_var.h>
|
---|
| 79 | #include <net/net_timer.h>
|
---|
| 80 |
|
---|
| 81 | #include <netinet/in.h>
|
---|
| 82 | #include <netinet/ip.h>
|
---|
| 83 | #include <netinet/ip6.h>
|
---|
| 84 | #include <netinet/udp.h>
|
---|
| 85 | #include <netinet/udp_var.h>
|
---|
| 86 | #include <netinet/in_itron.h>
|
---|
| 87 |
|
---|
| 88 | #include <netapp/netapp.h>
|
---|
| 89 | #include <netapp/netapp_var.h>
|
---|
| 90 | #include <netapp/discard.h>
|
---|
| 91 |
|
---|
| 92 | #ifdef USE_UDP_DISCARD_CLI
|
---|
| 93 |
|
---|
| 94 | /* discard ãµã¼ãã®ãã¼ãçªå· */
|
---|
| 95 |
|
---|
| 96 | #define DISCARD_SRV_PORTNO UINT_C(9)
|
---|
| 97 |
|
---|
| 98 | /*
|
---|
| 99 | * å¤æ°
|
---|
| 100 | */
|
---|
| 101 |
|
---|
| 102 | #define PAT_BEGIN ' '
|
---|
| 103 | #define PAT_END '~'
|
---|
| 104 |
|
---|
| 105 | /*
|
---|
| 106 | * å
|
---|
| 107 | ¨åå¤æ°
|
---|
| 108 | */
|
---|
| 109 |
|
---|
| 110 | bool_t udp_discard_cli_valid;
|
---|
| 111 |
|
---|
| 112 | /*
|
---|
| 113 | * send_udp_discard -- DISCARD/UDP ãµã¼ãã«ã¡ãã»ã¼ã¸ãéä¿¡ããã
|
---|
| 114 | */
|
---|
| 115 |
|
---|
| 116 | static ER
|
---|
| 117 | send_udp_discard (ID cepid, T_IN_ADDR *ipaddr, uint16_t portno)
|
---|
| 118 | {
|
---|
| 119 | static char smsg[IF_MTU - IP_UDP_HDR_SIZE];
|
---|
| 120 |
|
---|
| 121 | T_IPEP dst;
|
---|
| 122 | ER_UINT len;
|
---|
| 123 | SYSTIM time;
|
---|
| 124 | char *p;
|
---|
| 125 | uint32_t total;
|
---|
| 126 | uint16_t pat, slen, scount;
|
---|
| 127 |
|
---|
| 128 | dst.ipaddr = *ipaddr;
|
---|
| 129 | dst.portno = portno;
|
---|
| 130 |
|
---|
| 131 | p = smsg;
|
---|
| 132 | for (slen = IF_MTU - IP_UDP_HDR_SIZE; slen > 0; )
|
---|
| 133 | for (pat = PAT_BEGIN; slen > 0 && pat <= PAT_END; pat ++, slen --)
|
---|
| 134 | *p ++ = pat;
|
---|
| 135 |
|
---|
| 136 | get_tim(&time);
|
---|
| 137 | syslog(LOG_NOTICE, "[UDC:%02d SND] sending: %6ld, to: %s.%d",
|
---|
| 138 | cepid, time / SYSTIM_HZ, IP2STR(NULL, &dst.ipaddr), dst.portno);
|
---|
| 139 |
|
---|
| 140 | scount = total = 0;
|
---|
| 141 | udp_discard_cli_valid = true;
|
---|
| 142 | for (slen = IF_MTU - IP_UDP_HDR_SIZE; udp_discard_cli_valid && slen > 0; slen --) {
|
---|
| 143 | scount ++;
|
---|
| 144 | if ((len = UDP_SND_DAT(cepid, &dst, smsg, slen, TMO_FEVR)) < 0) {
|
---|
| 145 | syslog(LOG_NOTICE, "[UDC:%02d SND] send error: %s", cepid, itron_strerror(len));
|
---|
| 146 | return len;
|
---|
| 147 | }
|
---|
| 148 | else
|
---|
| 149 | syslog(LOG_NOTICE, "[UDC:%02d SND] send: %4d, %4d", cepid, scount, slen);
|
---|
| 150 | total += len;
|
---|
| 151 | dly_tsk(10 * SYSTIM_HZ + net_rand() % (10 * SYSTIM_HZ));
|
---|
| 152 | }
|
---|
| 153 |
|
---|
| 154 | get_tim(&time);
|
---|
| 155 | syslog(LOG_NOTICE, "[UDC:%02d SND] finished: %6ld, snd: %4d, len: %ld",
|
---|
| 156 | cepid, time / SYSTIM_HZ, scount, total);
|
---|
| 157 | return E_OK;
|
---|
| 158 | }
|
---|
| 159 |
|
---|
| 160 | /*
|
---|
| 161 | * UDP DISCARD ã¯ã©ã¤ã¢ã³ãéä¿¡ã¿ã¹ã¯
|
---|
| 162 | */
|
---|
| 163 |
|
---|
| 164 | void
|
---|
| 165 | udp_discard_cli_task (intptr_t exinf)
|
---|
| 166 | {
|
---|
| 167 | T_IN_ADDR addr;
|
---|
| 168 | ID tskid, cepid;
|
---|
| 169 | ER error;
|
---|
| 170 | char *line;
|
---|
| 171 | int_t no;
|
---|
| 172 | uint16_t portno;
|
---|
| 173 |
|
---|
| 174 | #ifdef USE_UDP_EXTENTIONS
|
---|
| 175 |
|
---|
| 176 | T_UDP_CCEP ccep;
|
---|
| 177 |
|
---|
| 178 | #endif /* of #ifdef USE_UDP_EXTENTIONS */
|
---|
| 179 |
|
---|
| 180 | get_tid(&tskid);
|
---|
| 181 | syslog(LOG_NOTICE, "[UDP DISCARD CLI:%d,%d] started.", tskid, (ID)exinf);
|
---|
| 182 | while (true) {
|
---|
| 183 | if (rcv_dtq(DTQ_UDP_DISCARD_CLI, (intptr_t*)&line) == E_OK) {
|
---|
| 184 | line = skip_blanks(GET_IPADDR(&addr, skip_blanks(line))); /* IP Address */
|
---|
| 185 |
|
---|
| 186 | if ('0' <= *line && *line <= '9') { /* Port No */
|
---|
| 187 | line = get_int(&no, line);
|
---|
| 188 | portno = (uint16_t)no;
|
---|
| 189 | }
|
---|
| 190 | else {
|
---|
| 191 | line ++;
|
---|
| 192 | portno = DISCARD_SRV_PORTNO;
|
---|
| 193 | }
|
---|
| 194 |
|
---|
| 195 | #ifdef USE_UDP_EXTENTIONS
|
---|
| 196 |
|
---|
| 197 | ccep.cepatr = UINT_C(0);
|
---|
| 198 | ccep.callback = NULL;
|
---|
| 199 | ccep.myaddr.portno = UDP_PORTANY;
|
---|
| 200 |
|
---|
| 201 | #if defined(SUPPORT_INET4)
|
---|
| 202 | ccep.myaddr.ipaddr = IPV4_ADDRANY;
|
---|
| 203 | #endif
|
---|
| 204 |
|
---|
| 205 | #if defined(SUPPORT_INET6)
|
---|
| 206 | memcpy(&ccep.myaddr.ipaddr, &ipv6_addrany, sizeof(T_IN6_ADDR));
|
---|
| 207 | #endif
|
---|
| 208 |
|
---|
| 209 | if ((error = alloc_udp_cep(&cepid, tskid, &ccep)) != E_OK) {
|
---|
| 210 | syslog(LOG_NOTICE, "[UDC:%02d TSK] CEP create error: %s", cepid, itron_strerror(error));
|
---|
| 211 | continue;
|
---|
| 212 | }
|
---|
| 213 |
|
---|
| 214 | #else /* of #ifdef USE_UDP_EXTENTIONS */
|
---|
| 215 |
|
---|
| 216 | cepid = (ID)exinf;
|
---|
| 217 |
|
---|
| 218 | #endif /* of #ifdef USE_UDP_EXTENTIONS */
|
---|
| 219 |
|
---|
| 220 | if ((error = send_udp_discard(cepid, &addr, portno)) != E_OK)
|
---|
| 221 | syslog(LOG_NOTICE, "[UDC:%02d TSK] error: %s", cepid, itron_strerror(error));
|
---|
| 222 |
|
---|
| 223 | #ifdef USE_UDP_EXTENTIONS
|
---|
| 224 |
|
---|
| 225 | if ((error = free_udp_cep(cepid, !(error == E_NOEXS || error == E_DLT))) != E_OK)
|
---|
| 226 | syslog(LOG_NOTICE, "[UDC:%02d TSK] CEP delete error: %s", cepid, itron_strerror(error));
|
---|
| 227 |
|
---|
| 228 | #endif /* of #ifdef USE_UDP_EXTENTIONS */
|
---|
| 229 |
|
---|
| 230 | }
|
---|
| 231 | }
|
---|
| 232 | }
|
---|
| 233 |
|
---|
| 234 | #endif /* of #ifdef USE_UDP_DISCARD_CLI */
|
---|