Implementing IPv6 ApplicationsImplementing IPv6 Applications

3y ago
45 Views
2 Downloads
982.55 KB
73 Pages
Last View : 10d ago
Last Download : 3m ago
Upload by : Xander Jaffe
Transcription

Implementing IPv6 Applications1

Intro We will explain how to implement IPv6 applications We assume knowledge of writing IPv4 applications We also look at porting IPv4 applications to IPv6 We look at writing/porting applications written in C , Perl,JJavaandd PHP We consider common application porting issues We lookl k at standardsd d andd recommendationsd

Enabling application for IPv6 MostM t IPv4IP 4 applicationsli tican beb IPv6IP 6 enabledbl d Appropriate abstraction layers used Providing ‘DualDual stackstack’ IPv4 and IPv6 is best Run-time (preferable) or compile-time network mode (v6 and/or v4) All widely used languages are IPv6-enabled E.g.E g C/C ,C/C Java,Java Python,Python Perl Some languages make it particularly easy e.g Java BenefitingBfiti ffrom IPIPv66 iis a littllittle more diffidifficultlt Though most functionality is the similar to IPv4 Add specialpfunctionalityy for IPv6 features IPv4 and IPv6 APIs have largely converged It is important for programmers to “think IPv6”: TTo speedd up IPv6IP 6 adoptiond ti Avoid risk of rolling out non compatible IPv6 programs once IPv6 willtake place

Precautions for Dual Stack Avoid any explicit use of IP addresses Normally do Call by Name Ensure that calls to network utilities are concentrated in one subroutine Ensure that libraries and utilities used support both stacks Do not request functions that would not exist in both stacks E.g. IPsec, MIP, Neighbour Discovery may vary

Dual stack configurationsBoth IPv4 and IPv6 stacks will be available during the transition periodDual network stack machine will allow to provide a service both for IPv4 and IPv62 different implementations of network stackSource : Rino Nucara, GARR, EuChinaGRID IPv6 Tutorial5

Mapping IPv4 address in IPv6IPv6/IPv4 Clients connecting to an IPv6 server at dual stack node Æ 1 socketDual StackSingle IPv4 or IPv6 stacksSource : Programming guidelines on transition to IPv6 T. P de Miguel, E. M. Castro6

IPv4-only and IPv6-onlyIPv6/IPv4 Clients connecting to an IPv4-only server and IPv6 only server atdual stack node Æ 2 socketsDual Stack or separated stackSingle IPv4 or IPv6 stacksSource : Programming guidelines on transition to IPv6 T. P de Miguel, E. M. Castro7

New Applications Simplified by writing apps using a high-level language E.g. JAVA seamlessly supports dual stack Design the application in a protocol independent fashion Ensure both protocols will be simultaneously operable

Implementingpg IPv6Porting The hardest part is often parsing of config files and internal handling ofaddresses, not the socket code itself You may need to write code that works with both old API and newnew. It’s not uncommon that large applications have some duplication ofnetwork code. When porting it might be a good idea to fix this If most parts are written in say Java, and small parts in say C, try torewrite C part to be in Java or at least make sure that I/O is concentratedin certain regions

Implementingpg IPv6Porting – Abstract Network Layer Separate the transport module from the rest of application functionalmodules– application independent on the network system used– if the network protocol is changed, only the transport module shouldbe modified The transport module should provide the communication channelabstraction with basic channel operations and generic data structures torepresent the addresses If a new network protocol is added, application developers only need toimplement a new instance of the channel abstraction which manages thef tfeaturesoff thithis new protocoltl

IPv6 literal addresses in URL’sFrom RFCC 2732Literal IPv6 Address Format in URL's Syntax To use a literal IPv6 address in a URL, the literaladdress should be enclosed in "[" and "]" characters. For example the following literal 9::836B:4179would be represented as in the following example :4179]

Effects on higher layers Affects anything that reads/writes/stores/passes IP addresses Most IETF protocols have been updated for IPv6 compliance Bigger IP header must be taken into account when computing maxpayloadl d sizesi Packet lifetime no longer limited by IP layer(it never was, anyway!) NewNDNS recordd type: AAAA DNS lookups may give several v4 and/or v6 addresses Applications may need to deal with multiple addresses Advanced mobility Mobile IPv6, Network Mobility (NEMO)

Implementingpg IPv6Miscellaneous issues (1) URL format for literal IPv6 addresses (RFC 2732)– http://[2001:db8:dead:beef::cafe]:80/ Entering IP addresses more difficult– Especially on a numeric/phone keypad Better to pass names than addresses in protocolsprotocols, referrals etcetc. They canlook up addresses in DNS and use what they need– If a dual-stack node can’t pass fqdn in protocol (referrals, sdp etc), itshould be able to pass both IPv4 and IPv6 addresses– Important that other clients can distinguish between IPv4 and IPv6belonging to same host, or being two different hosts In IPv4, we used variable-length subnet masks

Implementingpg IPv6Miscellaneous issues (2) Hosts will typically have several addresses– Dual-stack hosts both IPv4 and IPv6– MayM havehmultiplelti l IPv6IP 6 addressesdd Multihomed or global prefix ULA for internal Renumbering Addresses may change over time– Privacy addresses, e.g. every 24 hours– When renumbering

Conclusion Many existing applications are available in IPv6http://en.wikipedia.org/wiki/Comparison of IPv6 application supporthttp://ipv6.niif.hu/m/ipv6 apps db Porting applications to IPv6 is straightforward ProvidedP id d certaint i guidelinesid liare followedf lld Heterogeneous environments provide the mostchallengesh ll

C IPv6 API

Implementingpg IPv6Basic IPv6 socket programming Will go through API within RFC 3493 (Basic Socket Interface Extensions for IPv6)and give recommendations on how to use it The Advanced API is specified in RFC 3542 There is also POSIX, or The Single UNIX Specification, Version 3 athttp://www.unix.org/version3/online.html RFC and POSIX are roughly the same with some minor differences. Useful to lookat both

Implementingpg IPv6RFC 3493 - Basic Socket Interface Extensions for IPv6 Basic Socket Interface Extensions for IPv6– RFC 2553’s revision version– SupportStbbasici socketk t APIAPIs ffor IPIPv66– Introducing a minimum of change into the system and providingcompletepcompatibilitypy for existingg IPv4 applicationspp TCP/UDP application is Required using IPv6– New socket address structure– New address conversion functions– Some new socket options Extensions for advanced IPv6 features are defied in another document.document– RFC 2292: Advanced Socket API for IPv6

Implementingpg IPv6RFC 3542 Advanced Sockets Application ProgramInterface ((API)) for IPv6 Is the latest specification and is the successor to RFC2292. It iis oftenft referredfd tto as “2292bi“2292bis”” Defines interfaces for accessing special IPv6 packet information such asthe IPv6 header and the extension headers. Advanced APIs are also used to extend the capability of IPv6 raw socket

Socket API Changes Name to Address Translation FunctionsAddress Conversion FunctionsAddAddressDataD t StructuresSt tWildcard AddressesConstant AdditionsCore Sockets FunctionsSocket OptionsNew Macros

IPv6 Address Family and Protocol FamilyNew address family name AF INET6 is defined in sys/socket.h DistinguishesDi ii h betweenbsockaddr ink dd i andd sockaddr in6k dd i 6 AF INET6 is used as a first argument to the socket() New protocol family name PF INET6 is defined in sys/socket.h #defined PF INET6AF INET621

IPv6 Address StructureNew address structure in6 addr structure is defined in netinet/in.h structin6 addr {uint8 tt s6 addr[16];uint8s6 addr[16]; //* IPv6 address *//};22

Address Structures・ IPv4 struct sockaddr in・ IPv6 struct sockaddr in6・ IPv4/IPv6/ struct sockaddr storage23

Implementingpg IPv6Important definitions PF INET6, AF INET6 (PF INET, AF INET for IPv4)struct in6 addr {uint8 t s6 addr[16];/* IPv6 address */};struct sockaddr in6 {sa family tsin6 family;/* AF INET6 */in port tsin6 port;/* transport layer port # */uint32 tsin6 flowinfo; /* IPv6 flow information */struct in6 addr sin6 addr;/* IPv6 address */uint32 tsin6 scope id; /* set of interfaces for a scope */};not used (yet)– sin6 flowinfo– Will discuss sin6 scope id laterstruct sockaddr storage {sa family tss family;/* address family */charhss pad.d/* paddingdditto makek it llarge enoughh */};– Used when we need a struct to store any type of sockaddr

Implementingpg IPv6Address Data Structure:sockaddr storage In order to write portable and multiprotocol applications, another datastructure is defined: the new sockadd storage. This function is designed to store all protocol specific address structureswith the right dimension and alignment. Hence, portable applications should use the sockaddr storage structure tostore their addresses, both IPv4 or IPv6 ones. This new structure hides the specific socket address structure that theapplication is using.

Implementingpg IPv6Pass Addresses

Implementingpg IPv6Get Addresses

Implementingpg IPv6IPv6 loopback address ThThe IPv6IP 6 loopbacklb k addressddisi providedid d ini twotforms:fa globall b l variablei bl andda symbolic constant Applicationsppuse in6addr loopbackpas theyy would use INADDR LOOPBACKin IPv4 applications. For example, to open a TCP connection to the localtelnet server, an application could use the following code:struct sockaddr in6sockaddr in6 sin6;.sin6.sin6 family AF INET6;sin6 sin6 flowinfo 0;sin6.sin6 flowinfosin6.sin6 port htons(23);sin6.sin6 addr in6addr loopback; /* structure assignment */.if (connect(s, (struct sockaddr *) &sin6, sizeof(sin6)) 1). SecondSd way isi a symbolicb li constantt t namedd IN6ADDR LOOPBACK INIT:IN6ADDR LOOPBACK INIT#define IN6ADDR LOOPBACK INIT {{{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1}}}struct in6 addr loopbackaddr IN6ADDR LOOPBACK INIT;

Socket OptionsA number of new socket options are defined for IPv6: IPV6 UNICAST HOPSIPV6 MULTICAST HOPSIPV6 MULTICAST LOOPIPV6 JOIN GROUPIPV6 LEAVE GROUPIPV6 V6ONLYThe socket can be used to send and receive IPv6 packets only.Takes an int value ( but is a boolean option).By default is turned off.An example use of this option is to allow two versions of the same serverprocess to run on the same port, one providing service over IPv6, theother providing the same service over IPv4.29

Example Code30

Address Conversion Functions Address conversion functions (working with both IPv4 andIPv6 addresses) are used to switch between a binaryrepresentationt ti anddahhuman friendlyf i dl presentationt ti31

Core Socket FunctionsCore APIs Use IPv6 Family and Address Structures socket() Uses PF INET6Functions that pass addresses bind() connect() sendmsg() sendto()Functions that return addresses accept() recvfrom() recvmsg() getpeername()() getsockname()All the above function definitions are unchanged due to use of structsockaddrk dd andd addressddllengthh

Name to Address Translationggetaddrinfo()() Node name to address translation is done in a protocol independent waytakes as input a service name like “http” or a numeric port number like “80” as well as anFQDN and returns a list of addresses along with the corresponding port number.is very flexible and has several modes of operation.It returns a dynamically allocated linked list of addrinfo structurescontains useful information (for example, sockaddr structure ready for use).int getaddrinfo(const char *nodename, const char *servname, const struct addrinfo *hints,struct addrinfo **res);freeaddrinfo()() it frees addrinfo structure returned by getaddrinfo(), along with any additional storageassociated with those structuresvoid freeaddrinfo(struct(addrinfo *ai););getnameinfo() getnameinfo is the complementary function to getaddrinfo: it takes a socket address andreturns a character string describing the host and another character string describing theservice.int getnameinfo (const struct sockaddr *sa, socklen t salen,char *host, socklen t hostlen, char*service, socklen t servicelen, int flags);

Implementingpg IPv6Scope ID When using link local addresses a host with multiple interfaces need to knowwhich interface the address is for This is what sockaddr in6sockaddr in6’ss sin6sin6 scope idscope id is for getaddrinfo() can automatically fill this in when called with e.g.“www.kame.net%eth0” or “fe80::1234:5678%eth0” This notation is standardized, but the naming of interfaces are not

Porting application to IPv6 To port IPv4 applications in a multiprotocol environment, developersshould look out for these basic points Use DNS names instead of numerical addresses Replace incidental hardcoded addresses with other kinds Sequences of zeros can be replaced by double colons sequence :: only onetime per address, e.g. The previous address can be rewritten as2001:760:40ec::12:3a IIn theth IPIPv66 RFCRFCs andd documentation,dt tiththe minimumi isubnetb t maskk isi shownhas/64, but in some cases, like point to point connections, a smaller subnet (suchas /126) can be used. In numerical addressing, RFC2732 specifies that squared brackets delimit IPv6address to avoid mismatches with the port separator such ashttp://[2001:760:40ec::12.3a]:800035

Porting application to IPv6 Applications in a dualstack host prefer to use IPv6 address instead of IPv4 In IPv6, it is normal to have multiple addresses associated to an interface. InIPv4 no address is associated to a network interfaceIPv4,interface, while at least one (linklocal address) is in IPv6. All functions provided by broadcast in IPv4 are implemented on multicast inIP 6IPv6. The two protocols cannot communicate directly, even in dualstack hosts.There are some different methods to implementpsuch communication,, but theyyare out of scope of this document.36

Rewriting an application To rewrite an application with IPv6 compliant code, the first step is to findall IPv4dependent functions. A simple waya is to check the sosourcece and headeheader file withith UNIX grepg ep utility.tilit grep grep grep grepsockaddr in *c *.hin addrin addr *.c.c *.h.hinet aton *.c *.hgethostbyname *.c *.h・ DDeveloperslshouldh ld pay attentiontt ti tot hhardcodedd d d numericali l address,ddhosth tnames, and binary representation of addresses. It is recommended to made all network functions in a single filefile. It is also suggested to replace all gethostbyname with the getaddrinfofunction, a simple switch can be used to implement protocol dependentpart of the code.37

Simple old IPv4 TCP client/* borrowed from .pdf */struct hostent *hp;int i, s;structt t sockaddr ink dd i sin;is socket(AF INET, SOCK STREAM, IPPROTO TCP);hp gethostbyname("www.kame.net");for (i 0; hp- h addr list[i];hp h addr list[i]; i ) { /* not so common to loop through all */memset(&sin, 0, sizeof(sin));sin.sin family AF INET;sin sin len sizeof(sin); /* only on BSD */sin.sin lensin.sin port htons(80);memcpy(&sin.sin addr, hp- h addr list[i],hp- hhp h length);length);if (connect(s, &sin, sizeof(sin)) 0)continue;break;}

Simple IPv4/IPv6 TCP client/* borrowed from .pdf */struct addrinfo hints, *res,res, *res0;res0;int error, s;memset(&hints, 0, sizeof(hints));hints.ai family AF UNSPEC;hints.ai socktype SOCK STREAM;hints.ai socktypeSOCK STREAM;error getaddrinfo("www.kame.net", "http", &hints, &res0);if (error)errx(1, "%s", gai strerror(error));/* res0 holds addrinfo chain *///s -1;for (res res0; res; res res- ai next) {s socket(res- ai family, res- ai socktype, res- ai protocol);if (s 0)continue;error connect(s, res- ai addr, res- ai addrlen);if (error) {close(s);s -1;continue;}break;}freeaddrinfo(res0);if (s 0)die();

Simple old IPv4 TCP server/* from .pdf */int s;structtt sockaddr ink dd i sin;is socket(AF INET, SOCK STREAM, IPPROTO TCP);memset(&sin, 0, sizeof(sin));sin sin family AFsin.sin familyAF INET;INET;sin.sin len sizeof(sin); /* only on BSD */sin.sin port htons(80);if (bind(s, &sin, sizeof(sin)) sizeof(sin)) 0)exit(1);listen(s, 5);

Simple IPv4/IPv6 TCP server (1/2)/* from .pdf */struct addrinfo hints, *res, *res0;int s, i, on 1;memset(&hints, 0, sizeof(hints));hints.ai family AF UNSPEC;hints.ai socktype SOCK STREAM;hihints.ai flagsi fl AI PASSIVE;error getaddrinfo(NULL, "http", &hints, &res0);if (error) {fprintf(stderr, "%s",%s , gai strerror(error));gai strerror(error));exit(1);}/* res0 has chain of wildcard addrs */

Simple IPv4/IPv6 TCP server (2/2)/* borrowed from .pdf */i 0;for (res res0; res; res res- ai next) {s socket(res- ai family, res- ai socktype, res- ai protocol);if (s 0)continue;#ifdef IPV6 V6ONLYif (res- ai family AF INET6 && setsockopt(s, IPPROTO IPV6, IPV6 V6ONLY, &on,sizeof(on)) 0) {close(s);continue;}#endifif (bind(s,(bind(s res- aires ai addr,addr res- aires ai addrlen)addrlen) 0) {close(s);continue;}listen(s, 5);socktable[i] s;sockfamily[i ] res- ai family;}freeaddrinfo(res0);if (i 0)errx(1, "no bind() successful");/* select()/poll() across socktable[] */

One socket server example (1/2)With support for mapped addresses you can use a single IPv6 socketAlso single v4 or v6 socket if you only need to support one family or take family as anargument on startup//* from .pdfp //p//p/p *//int af AF INET6; /* or AF INET */struct addrinfo hints, *res;int s, i, on 1;memset(&hints, 0, sizeof(hints));hints.ai family af;hints.ai socktype SOCK STREAM;hints.ai flags AI PASSIVE;error getaddrinfo(NULL, "http", &hints, &res);if (error)exit(1);it(1)if (res- ai next) {fprintf(stderr, "multiple addr");exit(1);}/* res has chain of wildcard addrs */

One socket server example (2/2)/* borrowed from .pdf */s socket(res- ai family, res- ai socktype,res- ai protocol);if (s( 0)exit(1);#ifdef IPV6 V6ONLY/* on here for v6 onlyonly, set off for mapped addresses if applicable */if (res- ai family AF INET6 && setsockopt(s, IPPROTO IPV6, IPV6 V6ONLY,&on, sizeof(on)) 0) {close(s);continue;}#endifif (bind(s, res- ai addr, res- ai addrlen) 0)exit(1);listen(s, 5);freeaddrinfo(res);

Java IPv6 API

IPv6 Support in Java Java APIs are already IPv4/IPv6 compliant. IPv6 support in Java isavailable since 1.4.0 in Solaris and Linux machines and since 1.5.0 forWindows XP and 2003 server. IPv6 support in Java is automatic and transparent. Indeed nosource code change and no bytecode changes are necessary. Every Java applicationlis alreadyld IPv6 enabledbl d if:f It does not use hardcoded addresses (no direct references to IPv4 literaladdresses); All the address or socket information is encapsulated in the Java NetworkingAPI; Through setting system properties, address type and/or socket typepreferences can be set; It does not use nonspecific functions in the address translation.

Java Code Example - Server47

Java Code Example - Client48

IPv6 Support in Java For new applications Ipv6 specific new classes and APIs canbe used. InetAddress This class represents an IP address. It provides address storage,name-address translation methodsmethods, address conversion methodsmethods, aswell as address testing methods. In J2SE

We will explain how to implement IPv6 applications We assume knowledge of writing IPv4 applications We also look at porting IPv4 applications to IPv6 We look at writing/porting applications written in C , Perl, JdPHPJava and PHP We consider common application porting issues We lk dd d dlook at standards and recommendations

Related Documents:

ipv6 hello-interval eigrp 10 1. ipv6 hold-time eigrp 10 3. ipv6 authentication mode eigrp 10 md5. ipv6 authentication keychain - eigrp 10 eigrp. interface Vlan4. description Data VLAN for Access: ipv6 address 2001:DB8:CAFE:4::2/64. ipv6 nd prefix 2001:DB8:CAFE:4::/64 no-advertise. ipv6 nd managed-config-flag. ipv6 dhcp relay destination 2001 .

Legacy Applications ported to run over IPv6 – Usable also where there is IPv6 infrastructure New Applications developed for use over IPv4, IPv6 or coupled IPv4/IPv6 infrastructure – Requires transition tools of course New Applications developed for use over IPv4, IPv6 or coupled; uses potential of IPv6, runs over IPv4

Structure of IPv6 Protocol IPv4 and IPv6 Header Comparison IPv6 Extension Headers IPv6 Addressing Addressing Format Types of IPv6 addresses. 3 ICMPv6 and Neighbor Discovery Router Solicitation & Advertisement Neighbor Solicitation & Advertisement Duplicate Address Detection Multicast in IPv6 DHCP & DNS for IPv

7 IPv6 Technology IPv6 Benefits A summary of the Benefits of IPv6 are as follows: Scalability IPv6 has 128-bit address space, which is 4 times wider in bits in compared to IPv4's 32-bit address space. Security IPv6 includes security in the basic specification. IPv6 includes a Flow

2 Mobile Broadband IPv6 Service, MENOG 7 Qtel IPv6 Overview 2 Qtel IPv6 Mobile Broadband Background Building an IPv6 Mobile Broadband Service Lessons Learnt Next Steps IPv6 Mobile Broadband 1 May, 2010 1 Jul, 2010 1 Sep, 2010 1 Nov, 2010 Project Timeline IPv6 Connection to ISP Established 8 Jul, 2010

This document provides IPv6 address planning guidance for public administrations. It is intended to provide a framework that public administrations can use to learn the key differences between IPv6 and IPv4 addressing, design an IPv6 address structure, obtain IPv6 address space, deploy IPv6 addresses and manage IPv6 addresses.

Client IPv6 preference:-hb.db test resulted in client using IPv6 Client IPv6 capable:-h6.d4 test resulted in client using IPv6 Resolver IPv6 capable:-h4.d6 test resulted in DNS resolver using IPv6 AAAA queries seen:-Any test resulted in AAAA queries being directed at measurement DNS server

“Accounting is the art of recording, classifying and summarizing in a significant manner and in terms of money, transactions and events which are, in part at least, of a financial character, and interpreting the result thereof”. Definition by the American Accounting Association (Year 1966): “The process of identifying, measuring and communicating economic information to permit informed .