TDC561%20Network%20Programming - PowerPoint PPT Presentation

About This Presentation
Title:

TDC561%20Network%20Programming

Description:

... number of bytes in everything following the 40 byte header, or 0 for a Jumbogram. ... TLA: top-level aggregation. NLA: next-level. SLA: site-level ... – PowerPoint PPT presentation

Number of Views:11
Avg rating:3.0/5.0
Slides: 39
Provided by: camelia2
Category:

less

Transcript and Presenter's Notes

Title: TDC561%20Network%20Programming


1
TDC561 Network Programming
Week 9 IPv6 IPv6 Client-Server Programming
  • Camelia Zlatea, PhD
  • Email czlatea_at_cs.depaul.edu

2
References
  • 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

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
Next Header
Hop Limit
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.
  • 5f1bdf00ce3ee200002008002078e3e3
  • 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
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
IPv4 Address
FFFF
80 bits
32 bits
16 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) dont 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
IPv4 Address
0000
80 bits
32 bits
16 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
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_addr16

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 ltsys/socket.hgt
  • include ltnetdb.hgt

  • int getaddrinfo(const char nodename,
  • const char servname,
  • const struct addrinfo hints,
  • struct addrinfo res)

IPv4 IPv6
gethostbyname() getaddrinfo()
getservicebyname() getaddrinfo()
29
getnameinfo()
  • Extracting info about a connection is placed in
    getnameinfo()
  • Corresponding to getpeername/getsockname.
  • include ltsys/socket.hgt
  • include ltnetdb.hgt
  • int getnameinfo(const struct sockaddr sa,
  • socklen_t salen,
  • char host, size_t hostlen,
  • char serv, size_t servlen,
  • int flags)

IPv4 IPv6
getservbyport() getnameinfo()
getservbyname() getnameinfo()
getpeername() getnameinfo()
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 flags2000841ltUP,RUNNING,MULTICAST,I
    Pv6gt

31
Example Mixing IPv4 and IPv6
  • // Server.c
  • include ltstdio.hgt
  • include ltsys/types.hgt
  • include ltsys/socket.hgt
  • include ltnetinet/in.hgt
  • include ltnetdb.hgt
  • include ltarpa/inet.hgt
  • define bufsize 20
  • define queuesize 5
  • define true 1
  • define false 0

main () struct sockaddr_in6 cin char
bufferbufsize int sd, sd_client, addrlen,
yes1,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,res
ponse)) ! 0) printf("s",gai_strerror(err
)) return
32
Mixing IPv4 and IPv6
  • sd -1
  • for (ap response ap ! NULL apap-gtai_next)
  • if ((sd socket(ap-gtai_family,ap-gtai_socktype,
    ap-gtai_protocol)) -1)
  • continue
  • if (bind(sd,ap-gtai_addr,ap-gtai_addrlen) 0)
  • break // success
  • perror("bind")
  • close(sd)
  • sd -1
  • freeaddrinfo(response)

33
Mixing IPv4 and IPv6
  • while (true)
  • char hostname100,service100
  • 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)

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 ltstdio.hgt include ltsys/types.hgt include
ltsys/socket.hgt include ltnetinet/in.hgt include
ltnetdb.hgt include ltarpa/inet.hgt 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 bufferbufsize,ip6strINET6_ADDRSTRLEN
  • int sd,err,connected false
  • bzero(req,sizeof(struct addrinfo))
  • req.ai_family AF_UNSPEC
  • req.ai_socktype SOCK_STREAM

36
Mixing IPv4 and IPv6
  • for (ap ans ap ! NULL ap ap-gtai_next)
  • printf("Trying to connect to s
    s\n",HOST,sockaddr_ntop(ap-gtai_addr))
  • if ((sd socket(ap-gtai_family,ap-gtai_socktype,ap-
    gtai_protocol)) -1)
  • perror("socket")
  • exit(1)
  • if (connect(sd, ap-gtai_addr, ap-gtai_addrlen) gt
    0)
  • connected true
  • break
  • freeaddrinfo(ans)

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 addrbufINET6_ADDRSTRLEN
  • switch (sa-gtsa_family)
  • case AF_INET
  • addr ((struct sockaddr_in
    )sa)-gtsin_addr
  • break
  • case AF_INET6
  • addr ((struct sockaddr_in6
    )sa)-gtsin6_addr
  • break
  • default
  • / terminate the process abnormally
    /
  • abort()
Write a Comment
User Comments (0)
About PowerShow.com