1 / 38

TDC561 Network Programming

TDC561 Network Programming. Week 9: IPv6 IPv6 Client-Server Programming. Camelia Zlatea, PhD Email: czlatea@cs.depaul.edu. W. Richard Stevens, Network Programming : Networking API: Sockets and XTI, Volume 1, 2nd edition, 1998 (ISBN 0-13-490012-X) Chap. 7, 11, 19, 21, 22. References.

duboisk
Download Presentation

TDC561 Network Programming

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. TDC561 Network Programming Week 9: IPv6 IPv6 Client-Server Programming Camelia Zlatea, PhD Email: czlatea@cs.depaul.edu

  2. W. Richard Stevens, Network Programming : Networking API: Sockets and XTI, Volume 1, 2nd edition, 1998 (ISBN 0-13-490012-X) Chap. 7, 11, 19, 21, 22 References

  3. Motivation for IPv6 4 for IPv4 IPv4 Header Format 4 bytes (32 bits) HeaderLength Ver TOS Total Datagram Length Fragment Offset Flags Datagram ID TTL Protocol Checksum Basic Header 32 bit source address 32 bit destination address IP Options IP Options Payload (data portion) IPv4 - Variable Header, 32-bit addresses

  4. Motivation for IPv6 6 for IPv6 IPv6 Header Format 4 bytes (32 bits) Ver Traffic Class Flow Label Hop Limit Next Header Payload Length 128 bit source address Basic Header 128 bit destination address Payload (includes optional headers & data portion) IPv6 - Fixed Header, 128-bit addresses, Flow label

  5. Motivation for IPv6 • IPv6 supports very large address space • No shortage of IPv4 addresses within organizations • Showcase a variety of applications • Support for hand-held devices • IPv6 adopted as standard for 3G mobile networks • Support for IPv6 in Win2000 • Microsoft has technical preview of IPv6 with APIs and SDKs available for Win2000

  6. IPv6 Headers • Simpler header - faster processing by routers. • No optional fields - fixed size (40 bytes) • No fragmentation fields. • No checksum • Support for multiple headers • more flexible than simple “protocol” field.

  7. IPv6 Header Fields • VERS: 6 (IP version number) • Priority(Traffic Class): will be used in congestion control • Flow Label: experimental - sender can label a sequence of packets as being in the same flow. • Payload Length: number of bytes in everything following the 40 byte header, or 0 for a Jumbogram. • Next Header is similar to the IPv4 “protocol” field - indicates what type of header follows the IPv6 header. • Hop Limit is similar to the IPv4 TTL field (but now it really means hops, not time).

  8. Extension Headers • Routing Header - source routing • Fragmentation Header - supports fragmentation of IPv6 datagrams. • Authentication Header • Encapsulating Security Payload Header

  9. IPv6 availability • Generally available with (new) versions of most operating systems. • BSD, Linux, Solaris 8 • An option with Windows 2000/NT • Most routers can support IPV6

  10. IPv6 Design Issues • Overcome IPv4 scaling problem • lack of address space. • Flexible transition mechanism. • New routing capabilities. • Quality of service. • Security. • Ability to add features in the future.

  11. IPv6 Addresses • 128 bits - written as eight 16-bit hex numbers. 5f1b:df00:ce3e:e200:0020:0800:2078:e3e3 • High order bits determine the type of address.

  12. Motivation for IPv6 • Structured IPv6 header formats lead to design of fast and efficient routers • All headers (including optional headers) are 40 bytes long • In IPv4, header length varies from 20 to 60 bytes • Intermediate routers cannot fragment packet • Fragmentation is possible only at the source • Reduces routing overhead • No checksum performed on the header • Optional IPSEC header authentication can be used • Efficient address management in IPv6 • Relaxed schedules for Router upgrades

  13. Motivation for IPv6 • IPv6 Address assignment designed to support address aggregation • Smaller routing tables, easier to manage, more scalable, faster and efficient routers • Support for multicast addresses • Various standard multicast addresses are pre-defined • Useful for dynamically changing information on a given subset of routers/servers • e.g., Lease time for addresses assigned by DHCP servers can be easily modified with a controlled multicast sent to all-DHCP servers multicast address (useful for renumbering IP addresses)

  14. IPv6 Unicast Address Types • Link-local unicast addresses • Automatically assigned and used for localized communication • Pertinent only to routers and end-hosts on the local subnet • Site-local unicast address • Similar to IPv4 private addresses • Has relevance only within the given site • Site could refer to a given enterprise or a given geographic location • Packets bearing this address are not routed outside the scope of the site. continued...

  15. IPv6 Unicast Address Types • Aggregation of global unicast address • Unique address across all IP networks • Assigned by the Internet Service Provider • ISP gets the bundle of addresses from Regional Registries for Internet Numbers • Helps in address aggregation and smaller Internet routing tables • IPv4 addresses are not dependent on the ISP. Results in large Internet routing tables. • IP address aggregation is crucial for scaling

  16. IPv6 - Aggregate Global Unicast Address 3 13 32 16 64 001 TLA ID NLA ID SLA ID Interface ID TLA: top-level aggregation NLA: next-level SLA: site-level Interface ID is (typically) based on hardware MAC address

  17. IPv4-Mapped IPv6 Address • IPv4-Mapped addresses allow a host that support both IPv4 and IPv6 to communicate with a host that supports only IPv4. • The IPv6 address is based completely on the IPv4 address. • 80 bits of 0s followed by 16 bits of ones, followed by a 32 bit IPv4 Address: 0000 . . . 0000 FFFF IPv4 Address 80 bits 16 bits 32 bits

  18. Works with DNS • An IPv6 application asks DNS for the address of a host, but the host only has an IPv4 address. • DNS creates the IPv4-Mapped IPv6 address automatically. • Kernel understands this is a special address and really uses IPv4 communication.

  19. IPv4-Compatible IPv6 Address • An IPv4 compatible address allows a host supporting IPv6 to talk IPv6 even if the local router(s) don’t talk IPv6. • IPv4 compatible addresses tell endpoint software to create a tunnel by encapsulating the IPv6 packet in an IPv4 packet. • 80 bits of 0s followed by 16 bits of 0s, followed by a 32 bit IPv4 Address: 0000 . . . 0000 0000 IPv4 Address 80 bits 16 bits 32 bits

  20. Tunneling • done automatically by kernel when IPv4-Compatible IPv6 addresses are used IPv6 Host IPv6 Host IPv4 Routers IPv4 Datagram IPv6 Datagram

  21. Dual Server • Server that handle both IPv4 and IPv6. • The work is handled by the O.S. (which contains protocol stacks for both v4 and v6): • automatic creation of IPv6 address from an IPv4 client (IPv4-mapped IPv6 address).

  22. Dual Server IPv4 client IPv6 client TCP TCP IPv4 IPv4 IPv6 IPv6 Datalink Datalink IPv6 server IPv4-mapped IPv6 address TCP Datalink

  23. IPv6 Clients • If an IPv6 client specifies an IPv4 address for the server, the kernel detects and talks IPv4 to the server. • DNS support for IPv6 addresses can make everything work. • getaddrinfo() returns an IPv4 mapped IPv6 address for hosts that only support IPv4.

  24. IPv6 - IPv4 Programming • The kernel does the work, we can assume we are talking IPv6 to everyone! • In case we really want to know, there are some macros that determine the type of an IPv6 address. • We can find out if we are talking to an IPv4 client or server by checking whether the address is an IPv4 mapped address.

  25. IPv6 Sockets programming • New address family: AF_INET6 • New address data type: in6_addr • New address structure: sockaddr_in6 • IPv6-based client/server applications

  26. in6_addr struct in6_addr { uint8_t s6_addr[16]; };

  27. sockaddr_in6 struct sockaddr_in6 { uint8_t sin6_len; sa_family_t sin6_family; in_port_t sin6_port; uint32_t sin6_flowinfo; struct in6_addr sin6_addr; };

  28. getaddrinfo() • used both to look up hostnames, and to look up service names (port numbers) • does not use perror() to report errors, but its own function gai_strerror(). #include <sys/socket.h> #include <netdb.h> int getaddrinfo(const char *nodename, const char *servname, const struct addrinfo *hints, struct addrinfo **res);

  29. getnameinfo() • Extracting info about a connection is placed in getnameinfo() • Corresponding to getpeername/getsockname. #include <sys/socket.h> #include <netdb.h> int getnameinfo(const struct sockaddr *sa, socklen_t salen, char *host, size_t hostlen, char *serv, size_t servlen, int flags);

  30. Operating Systems - IPv6 Support • Some operating systems do not conform to the standard interfaces. • OpenBSD does not map IPv4 addresses to IPv6 ranges. • Windows winsock, • reported issues in supporting inet_ptoa. • alternative: getaddrinfo can be used to get around this (more expensive). • Standard way to find out interface configuration information about the ipv6 addresses • ifconfig/ipconfig. (SunOS , HP-UX, Linux versions , ..) • Example: % ifconfig le0 inet6 le0: flags=2000841<UP,RUNNING,MULTICAST,IPv6>

  31. Example: Mixing IPv4 and IPv6 main () { struct sockaddr_in6 cin; char buffer[bufsize]; int sd, sd_client, addrlen, yes=1,err; struct addrinfo query,*response,*ap; bzero(&query,sizeof(struct addrinfo)); query.ai_flags = AI_PASSIVE; query.ai_family = AF_UNSPEC; query.ai_socktype = SOCK_STREAM; if ((err = getaddrinfo(NULL,"servicename",&query,&response)) != 0) { printf("%s",gai_strerror(err)); return; } // Server.c #include <stdio.h> #include <sys/types.h> #include <sys/socket.h> #include <netinet/in.h> #include <netdb.h> #include <arpa/inet.h> #define bufsize 20 #define queuesize 5 #define true 1 #define false 0

  32. Mixing IPv4 and IPv6 sd = -1; for (ap = response ; ap != NULL; ap=ap->ai_next) { if ((sd = socket(ap->ai_family,ap->ai_socktype,ap->ai_protocol)) == -1) { continue; } if (bind(sd,ap->ai_addr,ap->ai_addrlen) == 0) { break; // success } perror("bind"); close(sd); sd = -1; } freeaddrinfo(response); if (sd < 0) { printf("Couldn't open bind an open socket\n"); exit(1); } if (listen(sd,queuesize) == -1) { perror("listen"); exit(1); }

  33. Mixing IPv4 and IPv6 while (true) { char hostname[100],service[100]; bzero(hostname,100); bzero(service,100); if ((sd_client = accept(sd,(struct sockaddr *)&cin,&addrlen)) == -1) { perror("accept"); exit(1); } if (getnameinfo((struct sockaddr *)&cin,addrlen,hostname,100,service,100,0) != 0) { perror("getnameinfo"); } printf("Connection received from host (%s) on remote port (%s)\n",hostname,service); bzero(buffer,20); if (recv(sd_client,buffer,sizeof(buffer),0) == -1) { perror("recv"); exit(1); }

  34. Mixing IPv4 and IPv6 // doWork(buffer) here if (send(sd_client,buffer,strlen(buffer),0) == -1) { perror("send"); exit(1); } close (sd_client); } close (sd); printf("Server closing down...\n"); }

  35. Mixing IPv4 and IPv6 #include <stdio.h> #include <sys/types.h> #include <sys/socket.h> #include <netinet/in.h> #include <netdb.h> #include <arpa/inet.h> #define HOST “hawk.depaul.edu" #define bufsize 20 #define false 0 #define true 1 // Client.c char *sockaddr_ntop(struct sockaddr *sa); main (argc,argv) int argc; char *argv[]; { struct sockaddr_in6 cin,cin2; struct addrinfo req, *ans, *ap; char buffer[bufsize],ip6str[INET6_ADDRSTRLEN]; int sd,err,connected = false; bzero(&req,sizeof(struct addrinfo)); req.ai_family = AF_UNSPEC; req.ai_socktype = SOCK_STREAM; // This port name has to exist, otherwise getaddrinfo fails if ((err = getaddrinfo(HOST,"servicename",&req,&ans)) != 0) { printf("Lookup error: %s\n",gai_strerror(err)); exit(0); }

  36. Mixing IPv4 and IPv6 for (ap = ans; ap != NULL; ap = ap->ai_next) { printf("Trying to connect to %s = %s\n",HOST,sockaddr_ntop(ap->ai_addr)); if ((sd = socket(ap->ai_family,ap->ai_socktype,ap->ai_protocol)) == -1) { perror("socket"); exit(1); } if (connect(sd, ap->ai_addr, ap->ai_addrlen) >= 0) { connected = true; break; } } freeaddrinfo(ans); if (connected) { sprintf(buffer,"%s + %s",argv[1],argv[3]); if (send(sd,buffer,strlen(buffer),0) == -1) { perror ("send"); exit(1); }

  37. Mixing IPv4 and IPv6 bzero(buffer,bufsize); if (recv(sd,buffer,bufsize,0) == -1) { perror("recv"); exit (1); } } printf ("Server responded with %s\n",buffer); close (sd); } char *sockaddr_ntop(struct sockaddr *sa)

  38. Mixing IPv4 and IPv6 char *sockaddr_ntop(struct sockaddr *sa) { void *addr; static char addrbuf[INET6_ADDRSTRLEN]; switch (sa->sa_family) { case AF_INET: addr = &((struct sockaddr_in *)sa)->sin_addr; break; case AF_INET6: addr = &((struct sockaddr_in6 *)sa)->sin6_addr; break; default: /* terminate the process abnormally */ abort(); } inet_ntop(sa->sa_family, addr, addrbuf, sizeof(addrbuf)); / * The inet_ntop() routine converts a numeric address into a string suitable for presentation. Can manipulate both IPv4 and IPv6 addresses */ return addrbuf; }

More Related