{"title":"funcptr - Linux","subtitle":"An engineer's technical notebook","link":[{"@attributes":{"rel":"self","type":"application\/atom+xml","href":"https:\/\/funcptr.net\/os\/linux\/atom.xml"}},{"@attributes":{"rel":"alternate","type":"text\/html","href":"https:\/\/funcptr.net\/"}}],"generator":"Zola","updated":"2015-07-08T19:54:43+00:00","id":"https:\/\/funcptr.net\/os\/linux\/atom.xml","entry":[{"title":"Cobbler with CentOS 7 failure to boot\/kickstart","published":"2015-07-08T19:54:43+00:00","updated":"2015-07-08T19:54:43+00:00","author":{"name":"Delta Regeer"},"link":{"@attributes":{"rel":"alternate","type":"text\/html","href":"https:\/\/funcptr.net\/2015\/cobbler-with-centos-7-failure-to-boot\/"}},"id":"https:\/\/funcptr.net\/2015\/cobbler-with-centos-7-failure-to-boot\/","content":"<p>Over the past week I've been working on building out an instance of Cobbler and\ntesting some of the provisioning that it is able to do. One of the operating\nsystems that I wanted to deploy is CentOS 7.<\/p>\n<p>After I imported the system into cobbler, it correctly showed up in the\npxelinux boot menu and it would happily load the kernel and the initrd, however\nafter initial bootup it would throw the following error message:<\/p>\n<pre class=\"giallo\" style=\"color: #D6DEEB; background-color: #011627;\" ><code data-lang=\"plain\"><span class=\"giallo-l\"><span>dracut-initqueue[867]: Warning: Could not boot.<\/span><\/span>\n<span class=\"giallo-l\"><span>dracut-initqueue[867]: Warning: \/dev\/root does not exist<\/span><\/span>\n<span class=\"giallo-l\"><\/span>\n<span class=\"giallo-l\"><span>         Starting Dracut Emergency Shell...<\/span><\/span>\n<span class=\"giallo-l\"><span>Warning: \/dev\/root does not exist<\/span><\/span>\n<span class=\"giallo-l\"><\/span>\n<span class=\"giallo-l\"><span>Generating &quot;\/run\/initramfs\/rdsosreport.txt&quot;<\/span><\/span>\n<span class=\"giallo-l\"><\/span>\n<span class=\"giallo-l\"><\/span>\n<span class=\"giallo-l\"><span>Entering emergency mode. Exit the shell to continue.<\/span><\/span>\n<span class=\"giallo-l\"><span>Type &quot;journalctl&quot; to view the system logs.<\/span><\/span>\n<span class=\"giallo-l\"><span>You might want to save &quot;\/run\/initramfs\/rdsosreport.txt&quot; to a USB stick or \/boot<\/span><\/span>\n<span class=\"giallo-l\"><span>after mounting them and attach it to a bug report<\/span><\/span><\/code><\/pre>\n<p>After that it gives you a root shell.<\/p>\n<p>Some Google searching led me to an <a rel=\"external\" href=\"https:\/\/web.archive.org\/web\/20160202155132\/https:\/\/lists.fedorahosted.org\/pipermail\/cobbler\/2014-August\/009647.html\">mailing list post for Cobbler<\/a> where\nsomeone mentioned that adding <code>ksdevice=link<\/code> to the Cobbler profile allowed\nthe system to boot without issues.<\/p>\n<p>However before I just implement a change I want to know why that fixes the\nissue, so I searched Google for \"kickstart ksdevice\" and found <a rel=\"external\" href=\"https:\/\/web.archive.org\/web\/20150923201114\/https:\/\/access.redhat.com\/documentation\/en-US\/Red_Hat_Enterprise_Linux\/6\/html\/Installation_Guide\/s1-kickstart2-startinginstall.html\">Red Hat's\ndocumentation on starting a kickstart<\/a>. Searching that page for \"ksdevice\"\nled me to this section:<\/p>\n<blockquote>\n<p><code>ksdevice=&lt;device&gt;<\/code><\/p>\n<p>The installation program uses this network device to connect to the network. You can specify the device in one of five ways:<\/p>\n<ul>\n<li>the device name of the interface, for example, <code>eth0<\/code><\/li>\n<li>the MAC address of the interface, for example, <code>00:12:34:56:78:9a<\/code><\/li>\n<li>the keyword <code>link<\/code>, which specifies the first interface with its link in the up state<\/li>\n<li>the keyword <code>bootif<\/code>, which uses the MAC address that pxelinux set in the\nBOOTIF variable. Set IPAPPEND 2 in your pxelinux.cfg file to have pxelinux\nset the BOOTIF variable.<\/li>\n<li>the keyword <code>ibft<\/code>, which uses the MAC address of the interface specified by iBFT<\/li>\n<\/ul>\n<p>For example, consider a system connected to an NFS server through the eth1\ndevice. To perform a kickstart installation on this system using a kickstart\nfile from the NFS server, you would use the command <code>ks=nfs:&lt;server&gt;:\/&lt;path&gt; ksdevice=eth1<\/code> at the boot: prompt.<\/p>\n<\/blockquote>\n<p>While <code>ksdevice=link<\/code> would work for some of the machines I am deploying, it\nwouldn't work for most since they have multiple interfaces and each one of\nthose interfaces would have link, what I really wanted was <code>ksdevice=bootif<\/code>,\nwhich is the most sensible default.<\/p>\n<p>So I modified the profile with <code>ksdevice=link<\/code> just to test, and that worked\nwithout issues, so then I modified the profile and added <code>ksdevice=link<\/code>, and\nthis failed.<\/p>\n<p>I figured I should check the <code>pxelinux.cfg\/default<\/code> file that Cobbler generates\nupon issuing a <code>cobbler sync<\/code> and verify that <code>ksdevice=bootif<\/code> is actually\nlisted correctly.<\/p>\n<p>What I found was this:<\/p>\n<pre class=\"giallo\" style=\"color: #D6DEEB; background-color: #011627;\" ><code data-lang=\"plain\"><span class=\"giallo-l\"><span>LABEL CentOS-7.1-x86_64<\/span><\/span>\n<span class=\"giallo-l\"><span>        kernel \/images\/CentOS-7.1-x86_64\/vmlinuz<\/span><\/span>\n<span class=\"giallo-l\"><span>        MENU LABEL CentOS-7.1-x86_64<\/span><\/span>\n<span class=\"giallo-l\"><span>        append initrd=\/images\/CentOS-7.1-x86_64\/initrd.img ksdevice=${net0\/mac} lang=  kssendmac text  ks=http:\/\/10.10.10.1\/cblr\/svc\/op\/ks\/profile\/CentOS-7.1-x86_64<\/span><\/span>\n<span class=\"giallo-l\"><span>        ipappend 2<\/span><\/span><\/code><\/pre>\n<p>This has a <code>ksdevice=${net0\/mac}<\/code> which is not what I had put in the profile,\noverwriting <code>ksdevice<\/code> in the profile with <code>ksdevice=link<\/code> did correctly put\nthat into the <code>pxelinux.cfg\/default<\/code> file, so Cobbler was overwriting my change\nsomehow.<\/p>\n<p>A quick search of <code>${net0\/mac}<\/code> led me to a page about <a rel=\"external\" href=\"http:\/\/etherboot.org\/wiki\/commandline\">gPXE commandline\nitems<\/a> that contained the same variable. At which point I remembered that in\nCobbler you set up your profile to be gPXE enabled or not. The default when you\nimport an image is to enable gPXE support.<\/p>\n<pre class=\"giallo\" style=\"color: #D6DEEB; background-color: #011627;\" ><code data-lang=\"plain\"><span class=\"giallo-l\"><span>cobbler profile report  --name=CentOS-7.1-x86_64<\/span><\/span>\n<span class=\"giallo-l\"><\/span>\n<span class=\"giallo-l\"><span>Name                           : CentOS-7.1-x86_64<\/span><\/span>\n<span class=\"giallo-l\"><span>TFTP Boot Files                : {}<\/span><\/span>\n<span class=\"giallo-l\"><span>Comment                        : <\/span><\/span>\n<span class=\"giallo-l\"><span>DHCP Tag                       : default<\/span><\/span>\n<span class=\"giallo-l\"><span>Distribution                   : CentOS-7.1-x86_64<\/span><\/span>\n<span class=\"giallo-l\"><span>Enable gPXE?                   : True<\/span><\/span>\n<span class=\"giallo-l\"><span>Enable PXE Menu?               : 1<\/span><\/span>\n<span class=\"giallo-l\"><span>[...]<\/span><\/span><\/code><\/pre>\n<p>So let's modify the profile to disable gPXE support:<\/p>\n<pre class=\"giallo\" style=\"color: #D6DEEB; background-color: #011627;\" ><code data-lang=\"shellscript\"><span class=\"giallo-l\"><span style=\"color: #82AAFF;font-style: italic;\">cobbler<\/span><span style=\"color: #ECC48D;\"> profile edit<\/span><span style=\"color: #82AAFF;\"> --name=CentOS-7.1-x86_64 --enable-gpxe=False<\/span><\/span>\n<span class=\"giallo-l\"><span style=\"color: #82AAFF;font-style: italic;\">cobbler<\/span><span style=\"color: #ECC48D;\"> sync<\/span><\/span><\/code><\/pre>\n<p>Verify that the change was made:<\/p>\n<pre class=\"giallo\" style=\"color: #D6DEEB; background-color: #011627;\" ><code data-lang=\"plain\"><span class=\"giallo-l\"><span>cobbler profile report  --name=CentOS-7.1-x86_64<\/span><\/span>\n<span class=\"giallo-l\"><\/span>\n<span class=\"giallo-l\"><span>[...]<\/span><\/span>\n<span class=\"giallo-l\"><span>Enable gPXE?                   : False<\/span><\/span>\n<span class=\"giallo-l\"><span>[...]<\/span><\/span><\/code><\/pre>\n<p>Then let's take a look at our <code>pxelinux.cfg\/default<\/code> file and make sure that it\nlooks correct:<\/p>\n<pre class=\"giallo\" style=\"color: #D6DEEB; background-color: #011627;\" ><code data-lang=\"plain\"><span class=\"giallo-l\"><span>LABEL CentOS-7.1-x86_64<\/span><\/span>\n<span class=\"giallo-l\"><span>        kernel \/images\/CentOS-7.1-x86_64\/vmlinuz<\/span><\/span>\n<span class=\"giallo-l\"><span>        MENU LABEL CentOS-7.1-x86_64<\/span><\/span>\n<span class=\"giallo-l\"><span>        append initrd=\/images\/CentOS-7.1-x86_64\/initrd.img ksdevice=bootif lang=  kssendmac text  ks=http:\/\/10.10.10.1\/cblr\/svc\/op\/ks\/profile\/CentOS-7.1-x86_64<\/span><\/span>\n<span class=\"giallo-l\"><span>        ipappend 2<\/span><\/span><\/code><\/pre>\n<p>This time our ksdevice is correctly set. Upon rebooting my PXE booted server it\npicked up the correct interface, made a DHCP request and kickstarted the server\nusing the provided kickstart file, and installation completed successfully.<\/p>\n<p>So unless you chain-boot gPXE from pxelinux by default, make sure that your\nprofiles are not set to be gPXE enabled if you want to use them directly from\nthe pxelinux menu.<\/p>\n<p>While researching more about this article, I found a blog post by <a rel=\"external\" href=\"https:\/\/web.archive.org\/web\/20160507142852\/https:\/\/blog.vladionescu.com\/pxe-installing-rhel-7-from-cobbler-2-6\/\">Vlad Ionescu\nabout PXE installing RHEL 7 from Cobbler<\/a> where he suggests disabling\n<code>ksdevice<\/code> entirely and adding an extra <code>inst.repo<\/code> variable to the kernel\ncommand line, however on older versions of CentOS 7 and Red Hat Enterprise\nLinux 7 there is a <a rel=\"external\" href=\"https:\/\/bugzilla.redhat.com\/show_bug.cgi?id=1096846\">bug report<\/a> that shows that an empty <code>ksdevice<\/code> could\ncause anaconda to crash, and setting a manual <code>inst.repo<\/code> for every profile\nseems like overkill when just disabling gPXE for the profile also solves the\nproblem.<\/p>\n"},{"title":"Neutron L3 agent with multiple provider networks","published":"2014-09-29T18:11:00+00:00","updated":"2014-09-29T18:11:00+00:00","author":{"name":"Delta Regeer"},"link":{"@attributes":{"rel":"alternate","type":"text\/html","href":"https:\/\/funcptr.net\/2014\/neutron-l3-agent-multiple-provider-networks\/"}},"id":"https:\/\/funcptr.net\/2014\/neutron-l3-agent-multiple-provider-networks\/","content":"<p>Due to requirements outside of my control, there was a requirement to run\nmultiple \"provider\" networks each with each providing their own floating\naddress pool from a single network node, I wanted to do this as simply as\npossible using a single l3 agent rather than having to figure out how to get\nsystemd to start multiple with different configuration files.<\/p>\n<p>Currently I've installed and configured an OpenStack instance that looks like\nthis:<\/p>\n<pre class=\"giallo\" style=\"color: #D6DEEB; background-color: #011627;\" ><code data-lang=\"plain\"><span class=\"giallo-l\"><span>+---------------------+<\/span><\/span>\n<span class=\"giallo-l\"><span>|                     |<\/span><\/span>\n<span class=\"giallo-l\"><span>|                  +--+----+<\/span><\/span>\n<span class=\"giallo-l\"><span>|                  |       |<\/span><\/span>\n<span class=\"giallo-l\"><span>|      +-----------+-+  +--+----------+<\/span><\/span>\n<span class=\"giallo-l\"><span>|      | Compute     |  | Compute     |<\/span><\/span>\n<span class=\"giallo-l\"><span>|      |     01      |  |     02      |<\/span><\/span>\n<span class=\"giallo-l\"><span>|      +------+------+  +-----+-------+<\/span><\/span>\n<span class=\"giallo-l\"><span>|             |               |<\/span><\/span>\n<span class=\"giallo-l\"><span>|             |               +----------+<\/span><\/span>\n<span class=\"giallo-l\"><span>|             +------------+--+          |<\/span><\/span>\n<span class=\"giallo-l\"><span>|                          |             |<\/span><\/span>\n<span class=\"giallo-l\"><span>| +-------------+    +-----+-------+     |<\/span><\/span>\n<span class=\"giallo-l\"><span>| | Controller  |    |   Network   |     |<\/span><\/span>\n<span class=\"giallo-l\"><span>| |             |    |             |     +---+  Tenant Networks (vlan tagged) (vlan ID&#39;s 350 - 400)<\/span><\/span>\n<span class=\"giallo-l\"><span>| +-----+----+--+    +------+----+-+<\/span><\/span>\n<span class=\"giallo-l\"><span>|       |    |              |    |<\/span><\/span>\n<span class=\"giallo-l\"><span>|       |    |              |    +-----------+  Floating Networks (vlan tagged) (vlan ID&#39;s 340 - 349)<\/span><\/span>\n<span class=\"giallo-l\"><span>|       |    |              |<\/span><\/span>\n<span class=\"giallo-l\"><span>|       |    |              |<\/span><\/span>\n<span class=\"giallo-l\"><span>+------------+--------------+----------------+  Management Network (10.5.2.0\/25)<\/span><\/span>\n<span class=\"giallo-l\"><span>        |<\/span><\/span>\n<span class=\"giallo-l\"><span>        |<\/span><\/span>\n<span class=\"giallo-l\"><span>        +------------------------------------+  External API Network (10.5.2.128\/25)<\/span><\/span><\/code><\/pre>\n<p>There are two compute nodes, a controller node that runs all of the API\nservices, and a network node that is strictly used for providing network\nfunctions (routers, load balancers, firewalls, all that fun stuff!).<\/p>\n<p>There are two flat networks that provide the following:<\/p>\n<ol>\n<li>External API access<\/li>\n<li>A management network that OpenStack uses internally to communicate between\ninstances and to manage it, which is not accessible from the other three\nnetworks.<\/li>\n<\/ol>\n<p>The other two networks are both vlan tagged:<\/p>\n<ol>\n<li>Tenant networks, with the possibility of 50 vlan ID's<\/li>\n<li>Floating networks, with existing vlan ID's for existing networks<\/li>\n<\/ol>\n<p>Since the OpenStack Icehouse release, the l3 agent has supported the ability to\nuse the Open vSwitch configuration to specify how traffic should be routed\nrather than statically defining that a single l3 agent routes certain traffic\nto a single Linux bridge. Setting this up is fairly simple if you follow the\ndocumentation, with one caveat, variables you think would be defined to no\nvalue, actually have a value and thus need to be explicitly zeroed out.<\/p>\n<h2 id=\"on-the-network-node\">On the network node<\/h2>\n<p>First, we need to configure the l3 agent, so let's set some extra variables in\n<code>\/etc\/neutron\/l3-agent.ini<\/code>:<\/p>\n<pre class=\"giallo\" style=\"color: #D6DEEB; background-color: #011627;\" ><code data-lang=\"ini\"><span class=\"giallo-l\"><span style=\"color: #C792EA;\">gateway_external_network_id<\/span><span> =<\/span><\/span>\n<span class=\"giallo-l\"><span style=\"color: #C792EA;\">external_network_bridge<\/span><span> =<\/span><\/span><\/code><\/pre>\n<p>It is important that these two are set, not left commented out, unfortunately\nwhen commented out they have some defaults set and it will fail to work, so\nexplicitly setting them to blank will fix that issue.<\/p>\n<p>Next, we need to set up our Open vSwitch configuration. In\n<code>\/etc\/neutron\/plugin.ini<\/code> the following needs to be configured:<\/p>\n<ul>\n<li><code>bridge_mappings<\/code><\/li>\n<li><code>network_vlan_ranges<\/code><\/li>\n<\/ul>\n<p>Note, that these may already be configured, in which case there is nothing left\nto do. Mine currently looks like this:<\/p>\n<pre class=\"giallo\" style=\"color: #D6DEEB; background-color: #011627;\" ><code data-lang=\"ini\"><span class=\"giallo-l\"><span style=\"color: #C792EA;\">bridge_mappings<\/span><span> = tenant1:br-tnt,provider1:br-ex<\/span><\/span><\/code><\/pre>\n<p>This basically specifies that any networks created under \"provider name\"\n<code>tenant1<\/code> are going to be mapped to the Open vSwitch bridge <code>br-tnt<\/code> and any\nnetworks with \"provider name\" <code>provider1<\/code> will be mapped to <code>br-ex<\/code>.<\/p>\n<p><code>br-tnt<\/code> is mapped to my tenant network and on the switch has vlan ID's 350 -\n400 assigned, and <code>br-ex<\/code> has vlan ID's 340 - 349 assigned.<\/p>\n<p>Following the above knowledge, my <code>network_vlan_ranges<\/code> is configured as such:<\/p>\n<pre class=\"giallo\" style=\"color: #D6DEEB; background-color: #011627;\" ><code data-lang=\"ini\"><span class=\"giallo-l\"><span style=\"color: #C792EA;\">network_vlan_ranges<\/span><span> = tenant1:350:400,provider1:340:349<\/span><\/span><\/code><\/pre>\n<p>Make sure to restart all neutron services:<\/p>\n<pre class=\"giallo\" style=\"color: #D6DEEB; background-color: #011627;\" ><code data-lang=\"shellscript\"><span class=\"giallo-l\"><span style=\"color: #82AAFF;font-style: italic;\">openstack-service<\/span><span style=\"color: #ECC48D;\"> restart neutron<\/span><\/span><\/code><\/pre><h2 id=\"on-the-controller-where-neutron-server-lives\">On the controller (where <code>neutron-server<\/code> lives)<\/h2>\n<p>On the controller we just need to make sure that our <code>network_vlan_ranges<\/code>\nmatches what is on the network node, with one exception, we do not list our\n<code>provider1<\/code> vlan ranges since we don't want to make those available to\naccidentally be assigned when a regular tenant creates a new network.<\/p>\n<p>So our configuration should list:<\/p>\n<pre class=\"giallo\" style=\"color: #D6DEEB; background-color: #011627;\" ><code data-lang=\"ini\"><span class=\"giallo-l\"><span style=\"color: #C792EA;\">network_vlan_ranges<\/span><span> = tenant1:350:400<\/span><\/span><\/code><\/pre>\n<p>Make sure that all neutron services are restarted:<\/p>\n<pre class=\"giallo\" style=\"color: #D6DEEB; background-color: #011627;\" ><code data-lang=\"shellscript\"><span class=\"giallo-l\"><span style=\"color: #82AAFF;font-style: italic;\">openstack-service<\/span><span style=\"color: #ECC48D;\"> restart neutron<\/span><\/span><\/code><\/pre><h2 id=\"create-the-neutron-networks\">Create the Neutron networks<\/h2>\n<p>Now, as an administrative user we need to create the provider networks.<\/p>\n<pre class=\"giallo\" style=\"color: #D6DEEB; background-color: #011627;\" ><code data-lang=\"shellscript\"><span class=\"giallo-l\"><span style=\"color: #C5E478;font-style: italic;\">source<\/span><span style=\"color: #ECC48D;\"> ~\/keystonerc_admin<\/span><\/span>\n<span class=\"giallo-l\"><\/span>\n<span class=\"giallo-l\"><span style=\"color: #82AAFF;font-style: italic;\">neutron<\/span><span style=\"color: #ECC48D;\"> net-create<\/span><span style=\"color: #D9F5DD;\"> &quot;<\/span><span style=\"color: #ECC48D;\">192.168.1.0\/24-floating<\/span><span style=\"color: #D9F5DD;\">&quot;<\/span><span style=\"color: #F78C6C;\"> \\<\/span><\/span>\n<span class=\"giallo-l\"><span style=\"color: #82AAFF;\">    --router:external<\/span><span style=\"color: #ECC48D;\"> True<\/span><span style=\"color: #F78C6C;\"> \\<\/span><\/span>\n<span class=\"giallo-l\"><span style=\"color: #82AAFF;\">    --provider:network_type<\/span><span style=\"color: #ECC48D;\"> vlan<\/span><span style=\"color: #F78C6C;\"> \\<\/span><\/span>\n<span class=\"giallo-l\"><span style=\"color: #82AAFF;\">    --provider:physical_network<\/span><span style=\"color: #ECC48D;\"> provider1<\/span><span style=\"color: #F78C6C;\"> \\<\/span><\/span>\n<span class=\"giallo-l\"><span style=\"color: #82AAFF;\">    --provider:segmentation_id<\/span><span style=\"color: #F78C6C;\"> 340<\/span><\/span>\n<span class=\"giallo-l\"><\/span>\n<span class=\"giallo-l\"><span style=\"color: #82AAFF;font-style: italic;\">neutron<\/span><span style=\"color: #ECC48D;\"> net-create<\/span><span style=\"color: #D9F5DD;\"> &quot;<\/span><span style=\"color: #ECC48D;\">192.168.2.0\/24-floating<\/span><span style=\"color: #D9F5DD;\">&quot;<\/span><span style=\"color: #F78C6C;\"> \\<\/span><\/span>\n<span class=\"giallo-l\"><span style=\"color: #82AAFF;\">    --router:external<\/span><span style=\"color: #ECC48D;\"> True<\/span><span style=\"color: #F78C6C;\"> \\<\/span><\/span>\n<span class=\"giallo-l\"><span style=\"color: #82AAFF;\">    --provider:network_type<\/span><span style=\"color: #ECC48D;\"> vlan<\/span><span style=\"color: #F78C6C;\"> \\<\/span><\/span>\n<span class=\"giallo-l\"><span style=\"color: #82AAFF;\">    --provider:physical_network<\/span><span style=\"color: #ECC48D;\"> provider1<\/span><span style=\"color: #F78C6C;\"> \\<\/span><\/span>\n<span class=\"giallo-l\"><span style=\"color: #82AAFF;\">    --provider:segmentation_id<\/span><span style=\"color: #F78C6C;\"> 341<\/span><\/span><\/code><\/pre>\n<p>Notice how we've created two networks, given them each individual names (I like\nto use the name of the network they are going to be used for) and have been\nattached to the <code>provider1<\/code>. Note that <code>provider1<\/code> is completely\nadministratively defined, and could just as well have been <code>physnet1<\/code>, so long\nas it is consistent across all of the configuration files.<\/p>\n<p>Now let's create subnets on this network:<\/p>\n<pre class=\"giallo\" style=\"color: #D6DEEB; background-color: #011627;\" ><code data-lang=\"shellscript\"><span class=\"giallo-l\"><span style=\"color: #82AAFF;font-style: italic;\">neutron<\/span><span style=\"color: #ECC48D;\"> subnet-create<\/span><span style=\"color: #D9F5DD;\"> &quot;<\/span><span style=\"color: #ECC48D;\">192.168.1.0\/24-floating<\/span><span style=\"color: #D9F5DD;\">&quot;<\/span><span style=\"color: #ECC48D;\"> 192.168.1.0\/24<\/span><span style=\"color: #F78C6C;\"> \\<\/span><\/span>\n<span class=\"giallo-l\"><span style=\"color: #82AAFF;\">    --allocation-pool<\/span><span style=\"color: #ECC48D;\"> start=192.168.1.4,end=<\/span><span style=\"color: #F78C6C;\">192.168.1.254 \\<\/span><\/span>\n<span class=\"giallo-l\"><span style=\"color: #82AAFF;\">    --disable-dhcp --gateway<\/span><span style=\"color: #F78C6C;\"> 192.168.1.1<\/span><\/span>\n<span class=\"giallo-l\"><\/span>\n<span class=\"giallo-l\"><span style=\"color: #82AAFF;font-style: italic;\">neutron<\/span><span style=\"color: #ECC48D;\"> subnet-create<\/span><span style=\"color: #D9F5DD;\"> &quot;<\/span><span style=\"color: #ECC48D;\">192.168.2.0\/24-floating<\/span><span style=\"color: #D9F5DD;\">&quot;<\/span><span style=\"color: #ECC48D;\"> 192.168.2.0\/24<\/span><span style=\"color: #F78C6C;\"> \\<\/span><\/span>\n<span class=\"giallo-l\"><span style=\"color: #82AAFF;\">    --allocation-pool<\/span><span style=\"color: #ECC48D;\"> start=192.168.2.4,end=<\/span><span style=\"color: #F78C6C;\">192.168.2.254 \\<\/span><\/span>\n<span class=\"giallo-l\"><span style=\"color: #82AAFF;\">    --disable-dhcp --gateway<\/span><span style=\"color: #F78C6C;\"> 192.168.2.1<\/span><\/span><\/code><\/pre>\n<p>Now that these networks are defined, you should be able to have tenants create\nrouters and set their gateways to either of these new networks by selecting\nfrom the drop-down in Horizon or by calling <code>neutron router-gateway-set &lt;router id&gt; &lt;network id&gt;<\/code> on the command line.<\/p>\n<p>The l3 agent will automatically configure and set up the router as required on\nthe network node, and traffic will flow to either vlan 340 or vlan 341 as\ndefined above depending on what floating network the user uses as a gateway.<\/p>\n<p>This drastically simplifies the configuration of multiple floating IP networks\nsince no longer is there a requirement to start up and configure multiple l3\nagents each with their own network ID configured. This makes configuration less\nbrittle and easier to maintain over time.<\/p>\n"},{"title":"OpenStack resizing of instances","published":"2014-09-29T17:10:00+00:00","updated":"2014-09-29T17:10:00+00:00","author":{"name":"Delta Regeer"},"link":{"@attributes":{"rel":"alternate","type":"text\/html","href":"https:\/\/funcptr.net\/2014\/openstack-resizing-instances\/"}},"id":"https:\/\/funcptr.net\/2014\/openstack-resizing-instances\/","content":"<p>One thing that is not always adequately explained in the OpenStack\ndocumentation is how exactly instance resizing works, and what is required,\nespecially while using KVM as the virtualisation provider, with multiple\ncompute nodes.<\/p>\n<p>You might find something similiar to the following in your logs, and no good\ndocumentation on how to fix it.<\/p>\n<pre class=\"giallo\" style=\"color: #D6DEEB; background-color: #011627;\" ><code data-lang=\"plain\"><span class=\"giallo-l\"><span>ERROR nova.compute.manager [req-7cb1c029-beb4-4905-a9d9-62d488540eda f542d1b5afeb4908b8b132c4486f9fa8 c2bfab5ad24642359f43cdff9bb00047] [instance: 99736f90-db0f-4cba-8f44-a73a603eee0b] Setting instance vm_state to ERROR<\/span><\/span>\n<span class=\"giallo-l\"><span>TRACE nova.compute.manager [instance: 99736f90-db0f-4cba-8f44-a73a603eee0b] Traceback (most recent call last):<\/span><\/span>\n<span class=\"giallo-l\"><span>TRACE nova.compute.manager [instance: 99736f90-db0f-4cba-8f44-a73a603eee0b]   File &quot;\/usr\/lib\/python2.7\/site-packages\/nova\/compute\/manager.py&quot;, line 5596, in _error_out_instance_on_exception<\/span><\/span>\n<span class=\"giallo-l\"><span>TRACE nova.compute.manager [instance: 99736f90-db0f-4cba-8f44-a73a603eee0b]     yield<\/span><\/span>\n<span class=\"giallo-l\"><span>TRACE nova.compute.manager [instance: 99736f90-db0f-4cba-8f44-a73a603eee0b]   File &quot;\/usr\/lib\/python2.7\/site-packages\/nova\/compute\/manager.py&quot;, line 3459, in resize_instance<\/span><\/span>\n<span class=\"giallo-l\"><span>TRACE nova.compute.manager [instance: 99736f90-db0f-4cba-8f44-a73a603eee0b]     block_device_info)<\/span><\/span>\n<span class=\"giallo-l\"><span>TRACE nova.compute.manager [instance: 99736f90-db0f-4cba-8f44-a73a603eee0b]   File &quot;\/usr\/lib\/python2.7\/site-packages\/nova\/virt\/libvirt\/driver.py&quot;, line 4980, in migrate_disk_and_power_off<\/span><\/span>\n<span class=\"giallo-l\"><span>TRACE nova.compute.manager [instance: 99736f90-db0f-4cba-8f44-a73a603eee0b]     utils.execute(&#39;ssh&#39;, dest, &#39;mkdir&#39;, &#39;-p&#39;, inst_base)<\/span><\/span>\n<span class=\"giallo-l\"><span>TRACE nova.compute.manager [instance: 99736f90-db0f-4cba-8f44-a73a603eee0b]   File &quot;\/usr\/lib\/python2.7\/site-packages\/nova\/utils.py&quot;, line 165, in execute<\/span><\/span>\n<span class=\"giallo-l\"><span>TRACE nova.compute.manager [instance: 99736f90-db0f-4cba-8f44-a73a603eee0b]     return processutils.execute(*cmd, **kwargs)<\/span><\/span>\n<span class=\"giallo-l\"><span>TRACE nova.compute.manager [instance: 99736f90-db0f-4cba-8f44-a73a603eee0b]   File &quot;\/usr\/lib\/python2.7\/site-packages\/nova\/openstack\/common\/processutils.py&quot;, line 193, in execute<\/span><\/span>\n<span class=\"giallo-l\"><span>TRACE nova.compute.manager [instance: 99736f90-db0f-4cba-8f44-a73a603eee0b]     cmd=&#39; &#39;.join(cmd))<\/span><\/span>\n<span class=\"giallo-l\"><span>TRACE nova.compute.manager [instance: 99736f90-db0f-4cba-8f44-a73a603eee0b] ProcessExecutionError: Unexpected error while running command.<\/span><\/span>\n<span class=\"giallo-l\"><span>TRACE nova.compute.manager [instance: 99736f90-db0f-4cba-8f44-a73a603eee0b] Command: ssh 10.5.2.20 mkdir -p \/var\/lib\/nova\/instances\/99736f90-db0f-4cba-8f44-a73a603eee0b<\/span><\/span>\n<span class=\"giallo-l\"><span>TRACE nova.compute.manager [instance: 99736f90-db0f-4cba-8f44-a73a603eee0b] Exit code: 255<\/span><\/span>\n<span class=\"giallo-l\"><span>TRACE nova.compute.manager [instance: 99736f90-db0f-4cba-8f44-a73a603eee0b] Stdout: &#39;&#39;<\/span><\/span>\n<span class=\"giallo-l\"><span>TRACE nova.compute.manager [instance: 99736f90-db0f-4cba-8f44-a73a603eee0b] Stderr: &#39;Host key verification failed.\\r\\n&#39;<\/span><\/span>\n<span class=\"giallo-l\"><span>TRACE nova.compute.manager [instance: 99736f90-db0f-4cba-8f44-a73a603eee0b] <\/span><\/span>\n<span class=\"giallo-l\"><span>ERROR oslo.messaging.rpc.dispatcher [-] Exception during message handling: Unexpected error while running command.<\/span><\/span>\n<span class=\"giallo-l\"><span>Command: ssh 10.5.2.20 mkdir -p \/var\/lib\/nova\/instances\/99736f90-db0f-4cba-8f44-a73a603eee0b<\/span><\/span>\n<span class=\"giallo-l\"><span>Exit code: 255<\/span><\/span>\n<span class=\"giallo-l\"><span>Stdout: &#39;&#39;<\/span><\/span>\n<span class=\"giallo-l\"><span>Stderr: &#39;Host key verification failed.\\r\\n&#39;<\/span><\/span><\/code><\/pre>\n<p>When OpenStack's nova is instructed to resize an instance it will also change\nthe host it is running on, almost never will it schedule the instance on the\nsame host and do the resize on the same host it already exists. There is a\nconfiguration flag to change this, however in my case I would rather the\nscheduler be run again, especially if the instance size is changing\ndrastically. During the resize process, the node where the instance is\ncurrently running will use SSH to connect to the instance where the resized\ninstance will live, and copy over the instance and associated files.<\/p>\n<p>There are a couple of assumptions I will be making:<\/p>\n<ol>\n<li>Your <code>nova<\/code>, and <code>qemu<\/code> user both have the same UID on all compute nodes<\/li>\n<li>The path for your instances is the same on all of your compute nodes<\/li>\n<\/ol>\n<h2 id=\"configure-the-nova-user\">Configure the nova user<\/h2>\n<p>First things first, let's make sure our <code>nova<\/code> user has an appropriate shell set:<\/p>\n<pre class=\"giallo\" style=\"color: #D6DEEB; background-color: #011627;\" ><code data-lang=\"shellscript\"><span class=\"giallo-l\"><span style=\"color: #82AAFF;font-style: italic;\">cat<\/span><span style=\"color: #ECC48D;\"> \/etc\/passwd<\/span><span style=\"color: #7FDBCA;\"> |<\/span><span style=\"color: #82AAFF;font-style: italic;\"> grep<\/span><span style=\"color: #ECC48D;\"> nova<\/span><\/span><\/code><\/pre>\n<p>Verify that the last entry is <code>\/bin\/bash<\/code>.<\/p>\n<p>If not, let's modify the user and make it so:<\/p>\n<pre class=\"giallo\" style=\"color: #D6DEEB; background-color: #011627;\" ><code data-lang=\"shellscript\"><span class=\"giallo-l\"><span style=\"color: #82AAFF;font-style: italic;\">usermod<\/span><span style=\"color: #82AAFF;\"> -s<\/span><span style=\"color: #ECC48D;\"> \/bin\/bash nova<\/span><\/span><\/code><\/pre><h2 id=\"generate-ssh-key-and-configuration\">Generate SSH key and configuration<\/h2>\n<p>After doing this the next steps are all run as the <code>nova<\/code> user.<\/p>\n<pre class=\"giallo\" style=\"color: #D6DEEB; background-color: #011627;\" ><code data-lang=\"shellscript\"><span class=\"giallo-l\"><span style=\"color: #82AAFF;font-style: italic;\">su<\/span><span style=\"color: #ECC48D;\"> - nova<\/span><\/span><\/code><\/pre>\n<p>We need to generate an SSH key:<\/p>\n<pre class=\"giallo\" style=\"color: #D6DEEB; background-color: #011627;\" ><code data-lang=\"shellscript\"><span class=\"giallo-l\"><span style=\"color: #82AAFF;font-style: italic;\">ssh-keygen<\/span><span style=\"color: #82AAFF;\"> -t<\/span><span style=\"color: #ECC48D;\"> rsa<\/span><\/span><\/code><\/pre>\n<p>Follow the directions, and save the key WITHOUT a passphrase.<\/p>\n<p>Next up we need to configure SSH to not do host key verification, unless you\nwant to manually SSH to all compute nodes that exist and accept the key (and\ncontinue to do so for each new compute node you add).<\/p>\n<pre class=\"giallo\" style=\"color: #D6DEEB; background-color: #011627;\" ><code data-lang=\"shellscript\"><span class=\"giallo-l\"><span style=\"color: #82AAFF;font-style: italic;\">cat<\/span><span style=\"color: #7FDBCA;\"> &lt;&lt;<\/span><span style=\"color: #D9F5DD;\"> EOF<\/span><span style=\"color: #7FDBCA;\"> &gt;<\/span><span style=\"color: #ECC48D;\"> ~\/.ssh\/config<\/span><\/span>\n<span class=\"giallo-l\"><span style=\"color: #ECC48D;\">Host *<\/span><\/span>\n<span class=\"giallo-l\"><span style=\"color: #ECC48D;\">    StrictHostKeyChecking no<\/span><\/span>\n<span class=\"giallo-l\"><span style=\"color: #ECC48D;\">    UserKnownHostsFile=\/dev\/null<\/span><\/span>\n<span class=\"giallo-l\"><span style=\"color: #D9F5DD;\">EOF<\/span><\/span><\/code><\/pre>\n<p>Next we need to make sure we copy the the contents of <code>id_rsa.pub<\/code> to\n<code>authorized_keys<\/code> and set the mode on it correctly.<\/p>\n<pre class=\"giallo\" style=\"color: #D6DEEB; background-color: #011627;\" ><code data-lang=\"shellscript\"><span class=\"giallo-l\"><span style=\"color: #82AAFF;font-style: italic;\">cat<\/span><span style=\"color: #ECC48D;\"> ~\/.ssh\/id_rsa.pub<\/span><span style=\"color: #7FDBCA;\"> &gt;<\/span><span style=\"color: #ECC48D;\"> .ssh\/authorized_keys<\/span><\/span>\n<span class=\"giallo-l\"><span style=\"color: #82AAFF;font-style: italic;\">chmod<\/span><span style=\"color: #F78C6C;\"> 600<\/span><span style=\"color: #ECC48D;\"> .ssh\/authorized_keys<\/span><\/span><\/code><\/pre>\n<p>This should be all the configuration for SSH you need to do. Now comes the\nimport part, you will need to tar up and copy the <code>~nova\/.ssh<\/code> directory to\nevery single compute node you have provisioned. This way all compute nodes will\nbe able to SSH to the remote host to run the commands required to copy an\ninstance over, and resize it.<\/p>\n<h2 id=\"reset-state-on-existing-error-ed-instances\">Reset state on existing ERROR'ed instances<\/h2>\n<p>If you have any instances that are currently in the <code>ERROR<\/code> state due to a\nfailed resize, you will be able to issue the following command to reset the\nstate back to running and try again:<\/p>\n<pre class=\"giallo\" style=\"color: #D6DEEB; background-color: #011627;\" ><code data-lang=\"shellscript\"><span class=\"giallo-l\"><span style=\"color: #82AAFF;font-style: italic;\">nova<\/span><span style=\"color: #ECC48D;\"> reset-state<\/span><span style=\"color: #82AAFF;\"> --active<\/span><span style=\"color: #7FDBCA;\"> &lt;<\/span><span style=\"color: #ECC48D;\">ID of instanc<\/span><span>e<\/span><span style=\"color: #7FDBCA;\">&gt;<\/span><\/span><\/code><\/pre>\n<p>This will start the instance, and you will be able to once again issue the\nresize command to resize the instance.<\/p>\n"},{"title":"IPv6 -- getaddrinfo() and bind() ordering with V6ONLY","published":"2012-08-07T22:39:56+00:00","updated":"2012-08-07T22:39:56+00:00","author":{"name":"Delta Regeer"},"link":{"@attributes":{"rel":"alternate","type":"text\/html","href":"https:\/\/funcptr.net\/2012\/ipv6-and-getaddrinfo\/"}},"id":"https:\/\/funcptr.net\/2012\/ipv6-and-getaddrinfo\/","content":"<p>Recently I ran into an issue that took me a while to sort out, and it is\nregarding inconsistent behaviour on various OS's with regards to IPv6 sockets\n(<a rel=\"external\" href=\"http:\/\/pubs.opengroup.org\/onlinepubs\/9699919799\/basedefs\/sys_socket.h.html\"><code>AF_INET6<\/code><\/a><sup class=\"footnote-reference\" id=\"fr-20120807afvspf-1\"><a href=\"https:\/\/funcptr.net\/2012\/ipv6-and-getaddrinfo\/#fn-20120807afvspf\">[1]<\/a><\/sup>) and calling <a rel=\"external\" href=\"http:\/\/www.freebsd.org\/cgi\/man.cgi?query=bind&amp;apropos=0&amp;sektion=2&amp;manpath=FreeBSD+9.0-RELEASE&amp;arch=default&amp;format=html\"><code>bind(2)<\/code><\/a> after getting the\nresults back from <a rel=\"external\" href=\"http:\/\/www.freebsd.org\/cgi\/man.cgi?query=getaddrinfo&amp;apropos=0&amp;sektion=3&amp;manpath=FreeBSD+9.0-RELEASE&amp;arch=default&amp;format=html\"><code>getaddrinfo(3)<\/code><\/a>.<\/p>\n<p>A call to <code>getaddrinfo()<\/code> with the hints set to <a rel=\"external\" href=\"http:\/\/pubs.opengroup.org\/onlinepubs\/9699919799\/basedefs\/sys_socket.h.html\"><code>AF_UNSPEC<\/code><\/a> in <code>ai_family<\/code>\nand <a rel=\"external\" href=\"http:\/\/www.freebsd.org\/cgi\/man.cgi?query=getaddrinfo&amp;apropos=0&amp;sektion=3&amp;manpath=FreeBSD+9.0-RELEASE&amp;arch=default&amp;format=html\"><code>AI_PASSIVE<\/code><\/a> in <code>ai_flags<\/code> will return to us 1 or more results that we\ncan <code>bind()<\/code> to. Sample code for that looks like this:<\/p>\n<pre class=\"giallo\" style=\"color: #D6DEEB; background-color: #011627;\" ><code data-lang=\"c\"><span class=\"giallo-l\"><span style=\"color: #C792EA;\">struct<\/span><span> addrinfo hints,<\/span><span style=\"color: #7FDBCA;\"> *<\/span><span>addrlist;<\/span><\/span>\n<span class=\"giallo-l\"><\/span>\n<span class=\"giallo-l\"><span style=\"color: #82AAFF;font-style: italic;\">memset<\/span><span>(<\/span><span style=\"color: #7FDBCA;\">&amp;<\/span><span style=\"color: #D7DBE0;\">hints<\/span><span>,<\/span><span style=\"color: #F78C6C;\"> 0<\/span><span>,<\/span><span style=\"color: #7FDBCA;\"> sizeof<\/span><span>(hints));<\/span><\/span>\n<span class=\"giallo-l\"><\/span>\n<span class=\"giallo-l\"><span style=\"color: #637777;font-style: italic;\">\/\/ Ask for TCP<\/span><\/span>\n<span class=\"giallo-l\"><span>hints.ai_socktype <\/span><span style=\"color: #C792EA;\">=<\/span><span> SOCK_STREAM;<\/span><\/span>\n<span class=\"giallo-l\"><\/span>\n<span class=\"giallo-l\"><span style=\"color: #637777;font-style: italic;\">\/\/ Any family works for us ...<\/span><\/span>\n<span class=\"giallo-l\"><span>hints.ai_family <\/span><span style=\"color: #C792EA;\">=<\/span><span> AF_UNSPEC;<\/span><\/span>\n<span class=\"giallo-l\"><\/span>\n<span class=\"giallo-l\"><span style=\"color: #637777;font-style: italic;\">\/\/ Set some hints<\/span><\/span>\n<span class=\"giallo-l\"><span>hints.ai_flags <\/span><span style=\"color: #C792EA;\">=<\/span><span> <\/span><\/span>\n<span class=\"giallo-l\"><span>    AI_PASSIVE    <\/span><span style=\"color: #7FDBCA;\">|<\/span><span style=\"color: #637777;font-style: italic;\"> \/\/ We want to use this with bind<\/span><\/span>\n<span class=\"giallo-l\"><span>    AI_ADDRCONFIG;<\/span><span style=\"color: #637777;font-style: italic;\">  \/\/ Only return IPv4 or IPv6 if they are configured<\/span><\/span>\n<span class=\"giallo-l\"><\/span>\n<span class=\"giallo-l\"><span style=\"color: #C792EA;\">int<\/span><span> rv;<\/span><\/span>\n<span class=\"giallo-l\"><\/span>\n<span class=\"giallo-l\"><span style=\"color: #C792EA;font-style: italic;\">if<\/span><span> ((rv <\/span><span style=\"color: #C792EA;\">=<\/span><span style=\"color: #82AAFF;font-style: italic;\"> getaddrinfo<\/span><span>(<\/span><span style=\"color: #F78C6C;\">0<\/span><span>,<\/span><span style=\"color: #D9F5DD;\"> &quot;<\/span><span style=\"color: #ECC48D;\">7020<\/span><span style=\"color: #D9F5DD;\">&quot;<\/span><span>,<\/span><span style=\"color: #7FDBCA;\"> &amp;<\/span><span style=\"color: #D7DBE0;\">hints<\/span><span>,<\/span><span style=\"color: #7FDBCA;\"> &amp;<\/span><span style=\"color: #D7DBE0;\">addrlist<\/span><span>))<\/span><span style=\"color: #C792EA;\"> !=<\/span><span style=\"color: #F78C6C;\"> 0<\/span><span>) {<\/span><\/span>\n<span class=\"giallo-l\"><span style=\"color: #82AAFF;font-style: italic;\">    fprintf<\/span><span style=\"color: #82AAFF;\">(stderr,<\/span><span style=\"color: #D9F5DD;\"> &quot;<\/span><span style=\"color: #ECC48D;\">getaddrinfo: <\/span><span style=\"color: #82AAFF;\">%s<\/span><span style=\"color: #D9F5DD;\">&quot;<\/span><span style=\"color: #82AAFF;\">,<\/span><span style=\"color: #82AAFF;font-style: italic;\"> gai_strerror<\/span><span style=\"color: #82AAFF;\">(rv))<\/span><span>;<\/span><\/span>\n<span class=\"giallo-l\"><span style=\"color: #C792EA;font-style: italic;\">    return<\/span><span style=\"color: #F78C6C;\"> 1<\/span><span>;<\/span><\/span>\n<span class=\"giallo-l\"><span>}<\/span><\/span>\n<span class=\"giallo-l\"><\/span>\n<span class=\"giallo-l\"><span style=\"color: #637777;font-style: italic;\">\/\/ Use the list in *addrlist<\/span><\/span>\n<span class=\"giallo-l\"><span style=\"color: #C792EA;font-style: italic;\">for<\/span><span> (addr <\/span><span style=\"color: #C792EA;\">=<\/span><span> addrlist; addr <\/span><span style=\"color: #C792EA;\">!=<\/span><span style=\"color: #F78C6C;\"> 0<\/span><span>; addr <\/span><span style=\"color: #C792EA;\">=<\/span><span> addr<\/span><span style=\"color: #7FDBCA;\">-<\/span><span style=\"color: #C792EA;\">&gt;<\/span><span>ai_next) {<\/span><\/span>\n<span class=\"giallo-l\"><span style=\"color: #637777;font-style: italic;\">    \/\/ use *addr as appropriate<\/span><\/span>\n<span class=\"giallo-l\"><span>}<\/span><\/span>\n<span class=\"giallo-l\"><\/span>\n<span class=\"giallo-l\"><span style=\"color: #637777;font-style: italic;\">\/\/ Clean up the memory from getaddrinfo()<\/span><\/span>\n<span class=\"giallo-l\"><span style=\"color: #82AAFF;font-style: italic;\">freeaddrinfo<\/span><span>(addrlist);<\/span><\/span><\/code><\/pre>\n<p>On Linux there are two entries returned when the host it is run on has both\nIPv4 and IPv6 enabled. An <code>AF_INET<\/code> which was followed by an <code>AF_INET6<\/code>. Now,\nit is not said that you are required to use all of the results that are\nreturned, but if you want to listen on all address families it is off course\nsuggested.<\/p>\n<p>Following the steps below for each of the returned results should result in\nhaving 1 or more different sockets that are bound to a single port.<\/p>\n<ol>\n<li>Create the socket()<\/li>\n<li>Set any socket options you want (<code>SO_REUSEADDR<\/code> for example)<\/li>\n<li>Then bind() the socket<\/li>\n<li>After that call listen() (followed off course by accept() on the socket)<\/li>\n<\/ol>\n<p>Only for some unknown reason (and <code>errno<\/code> is no help) <code>bind()<\/code> fails when you\nget to the <code>AF_INET6<\/code>, which was returned second. Searching online as to why\nthe bind would fail doesn't give you any good results and the thing that is\neven worse is that if you run the same code on another platform such as\n<a rel=\"external\" href=\"http:\/\/www.freebsd.org\">FreeBSD<\/a>, <a rel=\"external\" href=\"http:\/\/openindiana.org\">OpenIndiana<\/a> or <a rel=\"external\" href=\"https:\/\/web.archive.org\/web\/20120808044613\/http:\/\/www.apple.com\/osx\/\">Mac OS X<\/a> no such failure exists. However\nI started suspecting something was up when I started looking at the output from\n<code>netstat -lan | grep 7020<\/code> on Mac OS X. Where 7020 is the port I passed into\n<code>getaddrinfo()<\/code>.<\/p>\n<pre class=\"giallo\" style=\"color: #D6DEEB; background-color: #011627;\" ><code data-lang=\"plain\"><span class=\"giallo-l\"><span>tcp46      0      0  *.7020                 *.*  LISTEN     <\/span><\/span>\n<span class=\"giallo-l\"><span>tcp4       0      0  *.7020                 *.*  LISTEN <\/span><\/span><\/code><\/pre>\n<p>Wait a minute ... one of the sockets is on both IPv4 and on IPv6. Some more\ntime spent searching the internet I came across <a rel=\"external\" href=\"http:\/\/tools.ietf.org\/html\/rfc3493#page-22\">RFC 3493 section 5.3<\/a>,\nwhich is titled \"<code>IPV6_V6ONLY<\/code> option for <code>AF_INET6<\/code> Sockets\".<\/p>\n<blockquote>\n<p>As stated in section &lt;3.7 Compatibility with IPv4 Nodes&gt;, <code>AF_INET6<\/code> sockets\nmay be used for both IPv4 and IPv6 communications.  Some applications may\nwant to restrict their use of an <code>AF_INET6<\/code> socket to IPv6 communications\nonly.<\/p>\n<\/blockquote>\n<p>This was going down the right route, so I changed my code so that in the steps\nlisted above in number 2 I added the following code if the socket type is\n<code>AF_INET6<\/code>:<\/p>\n<pre class=\"giallo\" style=\"color: #D6DEEB; background-color: #011627;\" ><code data-lang=\"c\"><span class=\"giallo-l\"><span style=\"color: #C792EA;font-style: italic;\">if<\/span><span> (<\/span><span style=\"color: #82AAFF;font-style: italic;\">setsockopt<\/span><span>(sockfd, IPPROTO_IPV6, IPV6_V6ONLY,<\/span><span style=\"color: #7FDBCA;\"> &amp;<\/span><span style=\"color: #D7DBE0;\">yes<\/span><span>,<\/span><span style=\"color: #7FDBCA;\"> sizeof<\/span><span>(<\/span><span style=\"color: #C792EA;\">int<\/span><span>))<\/span><span style=\"color: #C792EA;\"> ==<\/span><span style=\"color: #7FDBCA;\"> -<\/span><span style=\"color: #F78C6C;\">1<\/span><span>) {<\/span><\/span>\n<span class=\"giallo-l\"><span style=\"color: #82AAFF;font-style: italic;\">    close<\/span><span style=\"color: #82AAFF;\">(sockfd)<\/span><span>;<\/span><\/span>\n<span class=\"giallo-l\"><span style=\"color: #82AAFF;font-style: italic;\">    fprintf<\/span><span style=\"color: #82AAFF;\">(stderr,<\/span><span style=\"color: #D9F5DD;\"> &quot;<\/span><span style=\"color: #ECC48D;\">setsockopt: <\/span><span style=\"color: #82AAFF;\">%s<\/span><span style=\"color: #ECC48D;\"> IPV6_V6ONLY<\/span><span style=\"color: #F78C6C;\">\\n<\/span><span style=\"color: #D9F5DD;\">&quot;<\/span><span style=\"color: #82AAFF;\">,<\/span><span style=\"color: #82AAFF;font-style: italic;\"> strerror<\/span><span style=\"color: #82AAFF;\">(errno))<\/span><span>;<\/span><\/span>\n<span class=\"giallo-l\"><span style=\"color: #C792EA;font-style: italic;\">    continue<\/span><span>;<\/span><\/span>\n<span class=\"giallo-l\"><span>}<\/span><\/span><\/code><\/pre>\n<p>The RFC 3493 section 5.3 also states that this option should be turned off by\ndefault, which means that all IPv6 sockets can also communicate over IPv4. Thus\ntechnically setting the option manually in code the best way to fix the issue.\nFreeBSD has had this feature turned on (as in IPv6 sockets can only communicate\nwith IPv6 and NOT IPv4) since 5.x.<\/p>\n<p>The biggest issue is that the remaining operating systems (OS X and\nOpenIndiana) don't have the same behaviour as Linux which makes troubleshooting\nthis issue more difficult than it should be. The issue is that the RFC doesn't\nspecify what exactly the operating should do when it encounters a request to\nbind to the same port on IPv4 and IPv6. The only place where I have found this\ndocumented is in <a rel=\"external\" href=\"http:\/\/www.amazon.com\/Network-Programming-Jun-ichiro-itojun-Hagino\/dp\/1555583180\">\"IPv6 Network Programming\"<\/a> under \"Tips in IPv6\nProgramming\" chapter 4, section 4, appropriately titled \"bind(2) Ordering and\nConflicts\".<\/p>\n<hr \/>\n<p>If you get a <code>bind()<\/code> error when attempting to bind to an <code>AF_INET6<\/code> socket\nplease make sure that you set the socket option <code>IPV6_V6ONLY<\/code> on the <code>AF_INET6<\/code>\nsocket. The default as required by RFC 3493 is to have that option be off. The\ndefault is wrong, and the RFC should have been more specific regarding what the\nright behaviour is when attempting to bind on an <code>AF_INET6<\/code> socket when already\nbound on an <code>AF_INET<\/code> while <code>IPV6_V6ONLY<\/code> is set to false.<\/p>\n<p>The full code that I used for testing, along with a little bit more information\nis available as a <a rel=\"external\" href=\"https:\/\/gist.github.com\/3231892\">gist on github<\/a>.<\/p>\n<section class=\"footnotes\">\n<ol class=\"footnotes-list\">\n<li id=\"fn-20120807afvspf\">\n<p>The old BSD style <a rel=\"external\" href=\"http:\/\/www.freebsd.org\/cgi\/man.cgi?query=socket&amp;apropos=0&amp;sektion=2&amp;manpath=FreeBSD+9.0-RELEASE&amp;arch=default&amp;format=html\"><code>socket()<\/code><\/a> called for defines\nstarting with <code>PF_<\/code> such as <code>PF_INET<\/code> and <code>PF_INET6<\/code> with the <code>PF<\/code> standing for\nprotocol family. POSIX starts them with <code>AF_<\/code>, and calls them an address\nfamily. On almost every operating system <code>PF_INET<\/code> is the same as <code>AF_INET<\/code>. If\nthe define doesn't exist you can always create it. <a href=\"https:\/\/funcptr.net\/2012\/ipv6-and-getaddrinfo\/#fr-20120807afvspf-1\">\u21a9<\/a><\/p>\n<\/li>\n<\/ol>\n<\/section>\n"}]}