Mercurial > ecos
comparison packages/net/common/current/src/ipv6_routing_thread.c @ 957:db3e0a2fda2f
2003-04-12 Andrew Lunn <andrew.lunn@ascom.ch>
* src/network_support.c (init_loopback_interface): Close the
socket when things go wrong otherwise we leak sockets.
* src/tftp_server.c (tftpd_server): Added support for IPv6 as well
as IPv4. Extended the multithreading support so that it works
correctly when there are multiple servers on multiple ports.
* doc/tcpip.sgml: Documentation for the changes made to the tftp
server.
2003-04-10 Andrew Lunn <andrew.lunn@ascom.ch>
* src/network_support.c (init_all_network_interfaces): Wait upto 4
seconds for a router solicit message to be received. Once we have
received the message we know we have a valid IPv6 address.
* src/tftp_client.c: Added support for IPv6. This requires two new
functions, tftp_client_{get|put} which are protocol version
independent.
* tests/tftp_client_test.c (tftp_test): Added tests which use IPv6
addresses.
2003-04-07 Andrew Lunn <andrew.lunn@ascom.ch>
* src/getaddrinfo.c (getaddrinfo): Correctly deal with node when
its not NULL. Its OK for the address to not parse for an address
family when AF_UNSPEC is passed in hints. Also get the socktype
correct when wildcarding for services that use UDP.
* tests/addr_test.c: Added more test cases which test IP addresses
in number format as node.
2003-04-05 Andrew Lunn <andrew.lunn@ascom.ch>
* cdl/net.cdl: Added addr_tests to the HW tests.
* tests/addr_test.c (net_test): void function not int.
* tests/ping_test.c (net_test): Added IPv6 ping test. This pings
the router which answers our router solicit message.
* src/ipv6_routing_thread.c (cyg_rs): Print out the router
advertisement message. Cleaned up the debug messages so they can
be disabled.
* src/ipv6_routing_thread.c (cyg_net_get_ipv6_advrouter): New
function to return the address of the router.
* include/network.h: Added prototype for above and
ipv6_start_routing_thread which did not have a prototype.
* src/ipv6_routing_thread.c (cyg_rs): Only wait 2 seconds before
sending the first solicit request rather than 10.
* src/dhcp_prot.c (do_dhcp_down_net): clear the if_laddrreq
before using it. If the request fails finish the IPv4 code rather
than returning,.
2003-04-02 Andrew Lunn <andrew.lunn@ascom.ch>
* tests/ping_lo_test.c: Added IPv6 ping test.
* src/getproto.c: Added the protocol ipv6-icmp.
| author | asl |
|---|---|
| date | Wed, 23 Apr 2003 08:52:08 +0000 |
| parents | 58c748750ca6 |
| children | 16d247bb9c70 |
comparison
equal
deleted
inserted
replaced
| 956:d9b26cfc0657 | 957:db3e0a2fda2f |
|---|---|
| 17 //####BSDCOPYRIGHTEND#### | 17 //####BSDCOPYRIGHTEND#### |
| 18 //========================================================================== | 18 //========================================================================== |
| 19 //#####DESCRIPTIONBEGIN#### | 19 //#####DESCRIPTIONBEGIN#### |
| 20 // | 20 // |
| 21 // Author(s): gthomas | 21 // Author(s): gthomas |
| 22 // Contributors: gthomas, lhamilton | 22 // Contributors: gthomas, lhamilton, andrew.lunn@ascom.ch |
| 23 // Date: 2002-04-16 | 23 // Date: 2002-04-16 |
| 24 // Purpose: | 24 // Purpose: |
| 25 // Description: | 25 // Description: |
| 26 // | 26 // |
| 27 // | 27 // |
| 56 #include <stdlib.h> | 56 #include <stdlib.h> |
| 57 #include <string.h> | 57 #include <string.h> |
| 58 | 58 |
| 59 void _show_all_interfaces(void); | 59 void _show_all_interfaces(void); |
| 60 | 60 |
| 61 #define DBG_PRINT 1 | 61 //#define DBG_PRINT 1 |
| 62 #define ALLROUTER "ff02::2" | 62 #define ALLROUTER "ff02::2" |
| 63 | 63 |
| 64 #define STACK_SIZE CYGNUM_HAL_STACK_SIZE_TYPICAL+2048 | 64 #define STACK_SIZE CYGNUM_HAL_STACK_SIZE_TYPICAL+2048 |
| 65 #define _1_MILLION 1000000 | 65 #define _1_MILLION 1000000 |
| 66 #define STATE_DELAY 0 | 66 #define STATE_DELAY 0 |
| 85 static struct timeval select_timeout; | 85 static struct timeval select_timeout; |
| 86 static struct timeval last_ra_time; | 86 static struct timeval last_ra_time; |
| 87 static struct timeval idle_expire; | 87 static struct timeval idle_expire; |
| 88 static struct icmp6stat *istat; | 88 static struct icmp6stat *istat; |
| 89 extern struct icmp6stat cyg_icmp6stat; | 89 extern struct icmp6stat cyg_icmp6stat; |
| 90 static struct sockaddr_in6 router; | |
| 91 static int router_valid = 0; | |
| 92 | |
| 93 // Return the address of the last router to send us a router advertisement | |
| 94 // Copy the address into addr and return true. If we have not received an | |
| 95 // advertisement yet, return false | |
| 96 int cyg_net_get_ipv6_advrouter(struct sockaddr_in6 * addr) { | |
| 97 | |
| 98 if (addr) { | |
| 99 memcpy(addr,&router,sizeof(*addr)); | |
| 100 } | |
| 101 return router_valid; | |
| 102 } | |
| 90 | 103 |
| 91 static void | 104 static void |
| 92 cyg_rs_exit(void) | 105 cyg_rs_exit(void) |
| 93 { | 106 { |
| 94 diag_printf("<%s>\n", __FUNCTION__); | 107 diag_printf("<%s>\n", __FUNCTION__); |
| 152 void | 165 void |
| 153 receive_ra_packet(void) | 166 receive_ra_packet(void) |
| 154 { | 167 { |
| 155 int len; | 168 int len; |
| 156 char msg[1024]; | 169 char msg[1024]; |
| 170 struct nd_router_advert *advert; | |
| 171 cyg_uint8 *opts; | |
| 172 int optlen; | |
| 173 int addrlen = sizeof(router); | |
| 174 char buf[64]; | |
| 157 | 175 |
| 158 dprnt("%s", __FUNCTION__); | 176 dprnt("%s", __FUNCTION__); |
| 159 | 177 |
| 160 len = read(s, msg, sizeof(msg)); | 178 len = recvfrom(s, msg, sizeof(msg),0,(struct sockaddr *)&router,&addrlen); |
| 161 if (len < 0) { | 179 if (len < 0) { |
| 162 dprnt(" Can't read RA data: %s", strerror(errno)); | 180 dprnt(" Can't read RA data: %s", strerror(errno)); |
| 163 return; | 181 return; |
| 164 } | 182 } |
| 183 router_valid = 1; | |
| 184 | |
| 185 inet_ntop(AF_INET6,(void *)&router.sin6_addr,buf,64); | |
| 186 dprnt("Router Advertisement from %s",buf); | |
| 165 dprnt("packet data (buf len=%d) :", len); | 187 dprnt("packet data (buf len=%d) :", len); |
| 188 #ifdef DBG_PRINT | |
| 166 diag_dump_buf(msg, len); | 189 diag_dump_buf(msg, len); |
| 167 | 190 #endif |
| 191 | |
| 192 advert = (struct nd_router_advert *)msg; | |
| 193 | |
| 194 dprnt("AdvCurHopLimit: %d", (int) advert->nd_ra_curhoplimit); | |
| 195 dprnt("AdvManagedFlag: %s", | |
| 196 (advert->nd_ra_flags_reserved & ND_RA_FLAG_MANAGED) ? "yes" : "no"); | |
| 197 dprnt("AdvOtherConfigFlag: %s", | |
| 198 (advert->nd_ra_flags_reserved & ND_RA_FLAG_OTHER) ? "yes":"no"); | |
| 199 dprnt("AdvHomeAgentFlag: %s", | |
| 200 (advert->nd_ra_flags_reserved & ND_RA_FLAG_HOME_AGENT) ? | |
| 201 "yes" : "no"); | |
| 202 dprnt("AdvReachableTime: %lu", | |
| 203 (unsigned long)ntohl(advert->nd_ra_reachable)); | |
| 204 dprnt("AdvRetransTimer: %lu", | |
| 205 (unsigned long)ntohl(advert->nd_ra_retransmit)); | |
| 206 | |
| 207 // Now process the optinal fields | |
| 208 len -= sizeof(*advert); | |
| 209 opts = (cyg_uint8 *)(msg + sizeof(struct nd_router_advert)); | |
| 210 | |
| 211 while (len > 0) { | |
| 212 optlen = (opts[1] << 3); | |
| 213 switch (*opts) { | |
| 214 case ND_OPT_MTU: { | |
| 215 struct nd_opt_mtu *mtu = (struct nd_opt_mtu *) opts; | |
| 216 | |
| 217 dprnt("AdvLinkMTU: %lu", | |
| 218 (unsigned long)ntohl(mtu->nd_opt_mtu_mtu)); | |
| 219 break; | |
| 220 } | |
| 221 case ND_OPT_PREFIX_INFORMATION: { | |
| 222 struct nd_opt_prefix_info *pinfo = (struct nd_opt_prefix_info *) opts; | |
| 223 | |
| 224 inet_ntop(AF_INET6,(void *)&pinfo->nd_opt_pi_prefix,buf,64); | |
| 225 dprnt("Prefix: %s/%d",buf,pinfo->nd_opt_pi_prefix_len); | |
| 226 break; | |
| 227 } | |
| 228 case ND_OPT_SOURCE_LINKADDR: { | |
| 229 char *cp = buf; | |
| 230 int i; | |
| 231 | |
| 232 for (i = 2 ; i < optlen ; i++) { | |
| 233 cp += diag_sprintf(cp,"%02x ", (unsigned int) opts[i]); | |
| 234 } | |
| 235 | |
| 236 dprnt("AdvSourceLinkAddress: %s",buf); | |
| 237 break; | |
| 238 } | |
| 239 case ND_OPT_ADVINTERVAL: | |
| 240 case ND_OPT_HOMEAGENT_INFO: | |
| 241 dprnt("Mobile IPv6 entension options (not decoded)"); | |
| 242 break; | |
| 243 default: | |
| 244 dprnt("Unknown option %d\n", (int)*opts); | |
| 245 break; | |
| 246 } | |
| 247 len -= optlen; | |
| 248 opts += optlen; | |
| 249 } | |
| 250 | |
| 168 racount++; | 251 racount++; |
| 169 get_realtime(&last_ra_time); | 252 get_realtime(&last_ra_time); |
| 170 dprnt("racount=%d, timestamp=%d sec", | 253 dprnt("racount=%d, timestamp=%d sec", |
| 171 racount, last_ra_time.tv_sec); | 254 racount, last_ra_time.tv_sec); |
| 172 | 255 |
| 249 struct timeval loop_delay; | 332 struct timeval loop_delay; |
| 250 int err, status; | 333 int err, status; |
| 251 u_int hlim = 255; | 334 u_int hlim = 255; |
| 252 fd_set fdset; | 335 fd_set fdset; |
| 253 | 336 |
| 337 #ifdef DBG_PRINT | |
| 254 _show_all_interfaces(); | 338 _show_all_interfaces(); |
| 339 #endif | |
| 255 | 340 |
| 256 memset(&hints, 0, sizeof(hints)); | 341 memset(&hints, 0, sizeof(hints)); |
| 257 hints.ai_family = AF_INET6; | 342 hints.ai_family = AF_INET6; |
| 258 err = getaddrinfo(ALLROUTER, NULL, &hints, &res); | 343 err = getaddrinfo(ALLROUTER, NULL, &hints, &res); |
| 259 if (err) { | 344 if (err) { |
| 287 } | 372 } |
| 288 | 373 |
| 289 idle_expire.tv_usec = 0; | 374 idle_expire.tv_usec = 0; |
| 290 select_timeout.tv_usec = 0; | 375 select_timeout.tv_usec = 0; |
| 291 last_ra_time.tv_usec = 0; | 376 last_ra_time.tv_usec = 0; |
| 292 last_ra_time.tv_sec = 10; | 377 last_ra_time.tv_sec = 2; |
| 293 select(0, 0, 0, 0, &last_ra_time); | 378 select(0, 0, 0, 0, &last_ra_time); |
| 294 | 379 |
| 295 racount = 0; | 380 racount = 0; |
| 296 istat = &(cyg_icmp6stat); | 381 istat = &(cyg_icmp6stat); |
| 297 badra = istat->icp6s_badra; | 382 badra = istat->icp6s_badra; |
