Are you ready for IPv6? Chris Kohlhoff

Outline: ●

IPv4 vs IPv6 – cheat sheet for developers



IPv6 support in Boost.Asio



Writing client programs



Writing server programs

IPv4 vs IPv6 Basics

IPv4 vs IPv6 Basics

Address ‒ binary representation IPv4

IPv6

32 bits

128 bits

IPv4 vs IPv6 Basics

Address ‒ string representation IPv4

IPv6

Dotted decimal address

Hex address

192.168.1.14

fec0:0:0:0:129a:ddff:fea7:529e

IPv4 vs IPv6 Basics

Address ‒ string representation IPv4

IPv6

Dotted decimal address

Hex address

192.168.1.14

fec0::129a:ddff:fea7:529e

At most one run of 0s may be “compressed”

IPv4 vs IPv6 Basics

Endpoint ‒ string representation IPv4

IPv6

192.168.1.14:12345

[fec0::129a:ddff:fea7:529e]:12345

IPv4 vs IPv6 Basics

Loopback address IPv4

IPv6

127.0.0.1

::1

IPv4 vs IPv6 Basics

Any address IPv4

IPv6

0.0.0.0

::

Sometimes you might also see 0::0

IPv6 Support in Boost.Asio

IPv6 Support in Boost.Asio

Principles: ●

Keep most user code independent of IP version



Avoid imposing dynamic memory allocation

IPv6 Support in Boost.Asio

Principles: ●

Keep most user code independent of IP version



Avoid imposing dynamic memory allocation

→ Use a variant approach

IPv6 Support in Boost.Asio

Resolver

Protocol

returns

Address

Endpoint Endpoint Endpoint

Port Number

IPv6 Support in Boost.Asio

Protocol: ●

For TCP, use asio::ip::tcp



For UDP, use asio::ip::udp

IPv6 Support in Boost.Asio udp my_protocol = udp::v4();

or udp my_protocol = udp::v6();

IPv6 Support in Boost.Asio udp my_protocol = udp::v4();

or udp my_protocol = udp::v6(); // ...

udp::socket sock(io_service, my_protocol);

IPv6 Support in Boost.Asio udp my_protocol = udp::v4();

or udp my_protocol = udp::v6(); // ...

udp::socket sock(io_service); sock.open(my_protocol);

IPv6 Support in Boost.Asio udp my_protocol = udp::v4();

or udp my_protocol = udp::v6(); // ...

if (my_protocol == udp::v6()) ...

IPv6 Support in Boost.Asio

Address: ●

Protocol independent ‒ asio::ip::address



IPv4 ‒ asio::ip::address_v4



IPv6 ‒ asio::ip::address_v6

IPv6 Support in Boost.Asio const char* ip_address_string = ...; address my_address = address::from_string(ip_address_string);

// ...

IPv4 dotted decimal or IPv6 hex address

std::string s = my_address.to_string();

IPv6 Support in Boost.Asio address my_address = address_v4::loopback(); // ... address my_address = address_v6::loopback();

IPv6 Support in Boost.Asio address my_address = address_v4::any(); // ... address my_address = address_v6::any();

IPv6 Support in Boost.Asio if (my_address.is_loopback()) ... New in Boost 1.47

if (my_address.is_unspecified()) ... if (my_address.is_multicast()) ...

IPv6 Support in Boost.Asio address_v4 my_address_v4 = ...; address my_address = my_address_v4; // ...

if (my_address.is_v4()) { address_v4 a = my_address.to_v4(); ... }

IPv6 Support in Boost.Asio address_v6 my_address_v6 = ...; address my_address = my_address_v6; // ...

if (my_address.is_v6()) { address_v6 a = my_address.to_v6(); ... }

IPv6 Support in Boost.Asio const char* ip_address_string = ...; address_v6 my_address_v6 = address_v6::from_string(ip_address_string);

// ...

IPv6 hex address only

std::string s = my_address_v6.to_string();

IPv6 Support in Boost.Asio address_v6::bytes_type raw_address_bytes; address_v6 my_address_v6(raw_address_bytes); // ...

address_v6::bytes_type bytes = my_address_v6.to_bytes();

array

IPv6 Support in Boost.Asio address_v4 my_address_v4 = ...; address_v6 my_address_v6 = address_v6::v4_mapped(my_address_v4);

// ... if (my_address_v6.is_v4_mapped()) { address_v4 a = my_address_v6.to_v4(); }

IPv6 Support in Boost.Asio address_v4 my_address_v4 = ...; address_v6 my_address_v6 = address_v6::v4_compatible(my_address_v4);

// ... if (my_address_v6.is_v4_compatible()) { address_v4 a = my_address_v6.to_v4(); }

IPv6 Support in Boost.Asio

Endpoint: ●

Always protocol independent



For TCP ‒ asio::ip::tcp::endpoint



For UDP ‒ asio::ip::udp::endpoint

IPv6 Support in Boost.Asio

Endpoint: ●

Always protocol independent



For TCP ‒ asio::ip::tcp::endpoint



For UDP ‒ asio::ip::udp::endpoint

Implemented as: template class basic_endpoint;

IPv6 Support in Boost.Asio udp::endpoint my_endpoint1(udp::v4(), 12345); // ... udp::endpoint my_endpoint2(udp::v6(), 12345); // ... address my_address = ...; udp::endpoint my_endpoint3(my_address, 12345);

IPv6 Support in Boost.Asio udp::endpoint my_endpoint = ...; // ... address my_address = my_endpoint.address(); // ... unsigned short my_port = my_endpoint.port(); // ... udp my_protocol = my_endpoint.protocol();

IPv6 Support in Boost.Asio

Resolver: ●



Obtain endpoints corresponding to host and service names Usually uses DNS

IPv6 Support in Boost.Asio udp::resolver::query my_query("host.name", "daytime"); // ... udp::resolver resolver(io_service); udp::resolver::iterator iter = resolver.resolve(my_query), end; while (iter != end) { cout << iter->endpoint() << std::endl; ++iter; }

One query can resolve to both IPv4 and IPv6 endpoints

IPv6 Support in Boost.Asio udp::resolver::query my_query1("host.name", "daytime"); // ... udp::resolver::query my_query2(udp::v4(), "host.name", "daytime"); // ... udp::resolver::query my_query3(udp::v6(), "host.name", "daytime");

IPv6 Support in Boost.Asio

Socket options: ● ●

Mostly protocol independent Automatically applies correct option based on socket's protocol

IPv6 Support in Boost.Asio udp::socket sock(io_service, my_protocol); // ...

sock.set_option(ip::unicast::hops(128));

For IPv4, uses IPPROTO_IP/IP_TTL For IPv6, uses IPPROTO_IPV6/IPV6_UNICAST_HOPS

Writing Client Programs

Writing Client Programs

Approaches for TCP clients: ●

Keep source code “protocol independent”



Prefer endpoints over addresses



Attempt connection to all available hosts

Writing Client Programs tcp::resolver resolver(io_service); tcp::resolver::query q("www.boost.org", "http"); tcp::resolver::iterator iter = resolver.resolve(q), end;

One query can resolve to multiple endpoints

Writing Client Programs tcp::resolver resolver(io_service); tcp::resolver::query q("www.boost.org", "http"); tcp::resolver::iterator iter = resolver.resolve(q), end;

tcp::socket sock(io_service); error_code ec = asio::error::not_found; while (iter != end && ec) { sock.close(ec); sock.connect(*iter, ec); ++iter; } if (ec) throw system_error(ec);

Try each endpoint until one works

Writing Client Programs tcp::resolver resolver(io_service); tcp::resolver::query q("www.boost.org", "http");

tcp::socket sock(io_service); asio::connect(sock, resolver.resolve(q));

New in Boost 1.47

Writing Client Programs tcp::resolver resolver(io_service); tcp::resolver::query q("www.boost.org", "http"); Reality check: IPv6 is vector endpoints( unlikely to be available yet resolver.resolve(q), tcp::resolver::iterator()); stable_partition(endpoints.begin(), endpoints.end(), is_ipv4); tcp::socket sock(io_service); error_code ec = asio::error::not_found; for (vector::iterator iter = endpoints.begin(); iter != endpoints.end() && ec; ++iter) { sock.close(ec); sock.connect(*iter, ec); } if (ec) throw system_error(ec); bool is_ipv4(const tcp::endpoint& endpoint) { return endpoint.protocol() == tcp::v4(); }

Writing Client Programs tcp::resolver resolver(io_service); tcp::resolver::query q("www.boost.org", "http"); vector endpoints( resolver.resolve(q), tcp::resolver::iterator()); stable_partition(endpoints.begin(), endpoints.end(), is_ipv4); tcp::socket sock(io_service); asio::connect(sock, endpoints.begin(), endpoints.end());

New in Boost 1.47

bool is_ipv4(const tcp::endpoint& endpoint) { return endpoint.protocol() == tcp::v4(); }

Writing Client Programs

Approaches for UDP clients: ●

Keep source code “protocol independent”



Use endpoints or addresses

Writing Client Programs const char* ip_address_string = ...; // IPv4 or IPv6 string representation udp::resolver resolver(io_service); udp::resolver::query q( ip_address_string, "50555", udp::resolver::query::numeric_host); udp::endpoint endpoint = *resolver.resolve(q); udp::socket sock(io_service); sock.open(endpoint.protocol()); sock.send_to(..., endpoint);

Writing Client Programs const char* ip_address_string = ...; // IPv4 or IPv6 string representation ip::address address = ip::address::from_string(ip_address_string); udp::endpoint endpoint(address, 50555);

udp::socket sock(io_service); sock.open(endpoint.protocol()); sock.send_to(..., endpoint);

Writing Server Programs

Writing Server Programs

The deployment environment: ●

Systems with both IPv4 and IPv6



Systems with IPv4 only

Writing Server Programs

The deployment environment: ●



Systems with both IPv4 and IPv6 ●

Dual stack



Separate stacks

Systems with IPv4 only

Writing Server Programs

The deployment environment is complex: ●

Systems with both IPv4 and IPv6 ●

Dual stack – –





Enabled by default Disabled by default

Separate stacks

Systems with IPv4 only

Writing Server Programs

Approaches for TCP servers: ●



Exactly one acceptor ●

Supports dual stack



Supports IPv6 only



Supports IPv4 only

Up to two acceptors ●

Supports all environments

Writing Server Programs

Exactly one acceptor: const char* listen_address = ...; // Typically "0.0.0.0" or "::" ip::address address = ip::address::from_string(listen_address); tcp::endpoint endpoint(address, 50555); tcp::acceptor acceptor(io_service, endpoint);

Writing Server Programs

Exactly one acceptor: const char* listen_address = ...; // Typically "0.0.0.0" or "::" ip::address address = ip::address::from_string(listen_address); tcp::endpoint endpoint(address, 50555); tcp::acceptor acceptor(io_service, endpoint.protocol()); if (endpoint.protocol() == tcp::v6()) { error_code ec; acceptor.set_option(ip::v6_only(false), ec); // Call succeeds only on dual stack systems. } acceptor.bind(endpoint); acceptor.listen();

Writing Server Programs

Up to two acceptors ‒ option 1: error_code ec; tcp::acceptor acceptor_v4(io_service); tcp::acceptor acceptor_v6(io_service); acceptor_v4.open(tcp::v4(), ec); if (!ec) { acceptor_v4.bind(tcp::endpoint(tcp::v4(), 50555)); acceptor_v4.listen(); } acceptor_v6.open(tcp::v6(), ec); if (!ec) { acceptor_v6.set_option(ip::v6_only(true)); acceptor_v6.bind(tcp::endpoint(tcp::v6(), 50555)); acceptor_v6.listen(); }

Writing Server Programs

Up to two acceptors ‒ option 2: ip::v6_only v6_only; acceptor_v6.open(tcp::v6(), ec); if (!ec) { acceptor_v6.get_option(v6_only); acceptor_v6.bind(tcp::endpoint(tcp::v6(), 50555)); acceptor_v6.listen(); } if (!acceptor_v6.is_open() || v6_only) { acceptor_v4.open(tcp::v4(), ec); if (!ec) { acceptor_v4.bind(tcp::endpoint(tcp::v4(), 50555)); acceptor_v4.listen(); } }

Writing Server Programs

Up to two acceptors ‒ option 3: ip::v6_only v6_only(false); acceptor_v6.open(tcp::v6(), ec); if (!ec) { acceptor_v6.set_option(v6_only, ec); acceptor_v6.get_option(v6_only); acceptor_v6.bind(tcp::endpoint(tcp::v6(), 50555)); acceptor_v6.listen(); } if (!acceptor_v6.is_open() || v6_only) { acceptor_v4.open(tcp::v4(), ec); if (!ec) { acceptor_v4.bind(tcp::endpoint(tcp::v4(), 50555)); acceptor_v4.listen(); } }

Writing Server Programs

Approaches for UDP servers: ●



Exactly one socket ●

Supports dual stack



Supports IPv6 only



Supports IPv4 only

Up to two sockets ●

Supports all environments

Writing Server Programs

Exactly one socket: const char* listen_address = ...; // Typically "0.0.0.0" or "::" ip::address address = ip::address::from_string(listen_address); udp::endpoint endpoint(address, 50555); udp::socket sock(io_service, endpoint);

Writing Server Programs

Exactly one socket: const char* listen_address = ...; // Typically "0.0.0.0" or "::" ip::address address = ip::address::from_string(listen_address); udp::endpoint endpoint(address, 50555); udp::socket sock(io_service, endpoint.protocol()); if (endpoint.protocol() == udp::v6()) { error_code ec; sock.set_option(ip::v6_only(false), ec); // Call succeeds only on dual stack systems. } sock.bind(endpoint);

Writing Server Programs

Up to two sockets ‒ option 1: error_code ec; udp::socket socket_v4(io_service); udp::socket socket_v6(io_service); socket_v4.open(udp::v4(), ec); if (!ec) { socket_v4.bind(udp::endpoint(udp::v4(), 50555)); } socket_v6.open(udp::v6(), ec); if (!ec) { socket_v6.set_option(ip::v6_only(true)); socket_v6.bind(udp::endpoint(udp::v6(), 50555)); }

Writing Server Programs

Up to two sockets ‒ option 2: ip::v6_only v6_only; socket_v6.open(udp::v6(), ec); if (!ec) { socket_v6.get_option(v6_only); socket_v6.bind(udp::endpoint(udp::v6(), 50555)); } if (!socket_v6.is_open() || v6_only) { socket_v4.open(udp::v4(), ec); if (!ec) { socket_v4.bind(udp::endpoint(udp::v4(), 50555)); } }

Writing Server Programs

Up to two sockets ‒ option 3: ip::v6_only v6_only(false); socket_v6.open(udp::v6(), ec); if (!ec) { socket_v6.set_option(v6_only, ec); socket_v6.get_option(v6_only); socket_v6.bind(udp::endpoint(udp::v6(), 50555)); } if (!socket_v6.is_open() || v6_only) { socket_v4.open(udp::v4(), ec); if (!ec) { socket_v4.bind(udp::endpoint(udp::v4(), 50555)); } }

Summary

Summary ●

Prefer protocol-independent approaches



Remember to try all endpoints



Choose designs appropriate to target environment

Are you ready for IPv6? - GitHub

Page 5 .... IPv6 Support in Boost.Asio. Resolver: ○ Obtain endpoints corresponding to host and service names. ○ Usually uses DNS ...

107KB Sizes 23 Downloads 282 Views

Recommend Documents

Prepping 2018 Are You Ready For Grid Down Survival.pdf ...
Page 1 of 2. Joe Ready. Prepping 2018 : Are You Ready For Grid Down Survival? readylifestyle.com/prepping-2018/. What are your plans for preparedness in 2018? We all have something that we can do to be. more prepared. Don't fall into the procrastinat

Are You Ready for the Holidays.pdf
Steubens Bread Winners Mighty Joes. Yak & Yeti The Bluegrass School House. Fazoli's Arvada Tavern Klines. 303 Ramen GB Fish & Chips Bada Bing. Ready to Walk the Runway. It's not the holiday season without the. holiday parties. Be pepared by finding t

Are Clouds Ready for Large Distributed Applications?
Page 1 ... Security and Network Components ... Transformation of existing enterprise service deployment into a cloud-based deployment. – Discovery of ...

bob harper are you ready pdf download
Page 1 of 1. Bob harper are you ready pdf download. Download now. Click here if your download doesn't start automatically. Page 1 of 1. bob harper are you ...

You Ready
n India's 60th. Independence Day in August 2007, Sun. Microsystems India had a special gift for all college students in India—a unique contest, which it aptly called Code. For Freedom. Here is what the company had to say: “Sixty years ago, India

Are You Ready for the Next Generation of Students? A ...
Sep 23, 2002 - Master's Degree. Bachelor's Degree. Bachelor's Degree and more. Associates Degree. Some college, no degree. High School graduate/GED.

Are Clouds Ready for Large Distributed Applications?
software procurement, base OS installation, middle-ware and ... For example, infrastructure as a service providers ... For example, RightScale [6] and 3Tera [5].

Are Clouds Ready for Large Distributed Applications?
What are users expecting from the cloud? –Establish a base-line for requirements. Is the cloud meeting user requirements? –Service deployment. –Service ...

Are Stationary Fuel Cells Ready for Market?
than expected rate for technology development. While prices have definitely fallen in recent years, uncertainty lingers regarding whether significant market ...

Are You suprised ?
became well known for his television appearances and his many opinion pieces in American newspapers. In addition, he founded several ... 2012. C: Complete the following: ( 6 points). 1. The Arab – American Culture Foundation was created by. 2. Shar

Are You suprised ?
D: What do the underlined pronouns refer to? ( 6 points). 1. There line ( 17 ). 2. Which line ( 11 ). E: 1. Give words from the text that have almost the same meaning as: ( 6 points). 1. make better : 2: concentrates : 3. fairness : 4: besides : 2. F

1 you are not what you were
ansSofteninto~ash'ip:CFOs,COQs,H;Hl&cor- prate cod, CMOS, public ndatiions dkxtors. Io~thatmrch~ownersbipisn'tpm-. lentWhynot?Perhapsirisbwd~~- sion except ta ~ t a b l e p m ~. rhesmaUsEte of the tinaanakdy4d OWW&@ table,nega-. -tiow. &out non-limme

You Are Where You Live - Esri
the most popular sections are the front page and local news .... more than 10 percent of households own- ...... found on Facebook, their social media platform of ...

1 you are not what you were
prate cod, CMOS, public ndatiions. M- dozen laealtficafe firms add their mrbdy named planning groups including NBBI; ZCrE* HDR, and. Steflian Bradley.

are you ready to become a homeowner? minimum ... - City of Mobile
COMMUNITY PLANNING & DEVELOPMENT DEPARTMENT ... The City of Mobile's Down Payment Assistance program provides First-time Homebuyers up to ...

pdf-1818\are-you-ready-to-play-outside-elephant-piggie ...
Try one of the apps below to open or edit this item. pdf-1818\are-you-ready-to-play-outside-elephant-piggie-books-japanese-edition-by-mo-willems.pdf.

IPv6 Transition for VzW
Each device will have Two IP Addresses. – VoIP (v6 Always On). – Internet/ASP (v6 or v4) ... competence. • Training is critical. – Academic. – Web-based classes.

College Ready for Some or Career Ready for All
than half actually graduate.2 These students need to be taught marketable 21st century skills ... k12/career-technical-education.edu.html. Programs of. Study are ...

Are You suprised
ABSTRACT. The new field of testing of timed-IUT (Implementation. Under Test with time constraints) is rapidly evolving, with new and extended test generation methods using timed automata. In all methods, however, it is assumed that the test is conduc