Triggering HomeKit Automations with a Fortigate

Problem Statement and Proposed solution

I use Apple HomeKit as my smart home platform of choice. Its not perfect and doesn’t have nearly the ecosystem that Alexa does but I like it and it compliments the fact that I use mostly Apple devices in the rest of my network. I don’t do anything all that complicated because I rent so there is a limit to the amount of smarts I can integrate. One feature I do like is the ability to automatically turn on and off an accessory (in my case lamps) based on if someone is home or not. HomeKit has a built in function for this that uses iPhone location data of people who have joined your home to determine if someone is there. The geofence size is pretty big and I live in a densely populated part of NYC where I might very well go to a store or other location that is not outside the geofence accuracy circle and my automation would never fire. I wanted something more accurate. The solution I came up with was to track if my or my partners iPhone is connected to the Wifi in the apartment. That gives a much smaller geofence and accomplishes my goal.

Enter Homebridge

Since I’m trying to do something that HomeKit doesn’t do natively I need to add 3rd party software to accomplish the wifi monitoring. I use Homebridge. Homebridge is an open source project that emulates a HomeKit bridge device and accepts plugins to interact with devices and platforms that HomeKit doesn’t natively support. I’m not going to go deeply into how to do the base install and setup of Homebridge. There are many good guides. One thing to note – as you search for Homebridge info you may see references to HOOBS. HOOBS is a scaled back, simpler, easier to use version of Homebridge with many capabilities and plugins being incompatible. While it may be a little easier to setup its worth taking the plunge and getting full Homebridge working.

Unifi Plugin

Prior to having a Fortigate/FortiAP combo for my home network I used Ubiquiti Unifi network equipment. Unifi is a pro-sumer brand that gives you a more robust and expandable system then the Netgears and Linksys’ of the world but less so than an enterprise brand like Fortigate or Palo Alto. Since Unifi is more common in the consumer space it has a better community of home-oriented developers writing software for it. There is a plugin called homebridge-unifi-occupancy-sensor that did exactly what I wanted. It polled the Ubiquiti controller using a REST call on a regular basis (5-10 seconds) and looked for the MAC address of one of our iPhones. If one or more of them were detected it would trigger what appears to HomeKit as an occupancy sensor saying that the Living Room was occupied. The occupancy sensor was used as a trigger for an automation to enable a scene with the Living Room lights on. Nice and easy.

Moving to Fortigate

Now that I have a Fortigate I wanted to accomplish the same thing. Since Fortigate isn’t usually a consumer device there are no Homebridge plugins for it at all. I had to figure out a different method. I tried a couple of plugins that used ping or ARP to determine if a machine was on the network but they had a lot of limitations and didn’t operate fast enough to have an elegant user experience (and in the case of one plugin a misconfiguration filled the ARP table on my core server and crashed it). I needed a way to directly determine based on the Fortigate if the iPhone was connected. There was no REST call or SNMP query I could find that would allow me to poll so I needed it to be a push from the Fortigate to Homebridge when one of us connected or disconnected. Enter Automation Stiches

Automation Stiches

Automation Stiches are an IF/THEN framework for Fortigates that allow actions to be taken based on triggers from the OS. Examples of triggers are detecting an intrusion, a process running out of memory, an interface state changing, or what I needed: an event log entry. Then I needed an action that would signal Homebridge and the Fortigate provided: the action can be a Webhook. There is a Homebridge plugin called homebridge-http-webhook that has the ability to present to HomeKit as an occupancy sensor (among other device types) which can be marked occupied or unoccupied based on receiving a particularly crafted HTTP request.

Create the Trigger

I needed two triggers one for each iPhone. The easiest way to identify them was by their Wifi MAC address. NOTE: For this to work you have to turn off “Private Wi-Fi Address” for your home SSID on the iPhone settings. If you don’t, there will not be a consistent MAC address to track and your automation will never fire.

I searched through the Wifi Event log and found the message (action: client-authentication) that indicates a client has successfully authenticated to my SSID. That message also contains the MAC of the device so that’s the one we want

Now navigate to Security Fabric -> Automation -> Trigger (Trigger is a tab at the top) and create a new trigger of type FortiOS Event Log

The details are filled in as follows

Note the event and filter. The event is the friendly/description name of the log event ID we identified above. If we used that event without a filter then ANY device joining the network would trigger this item we need to only use that event ID if it is for my iPhone. The field filter is using the name “stamac” which was not a field in the screenshot above. You can map the friendly names of the fields to their short names by checking the Fortigate Log Reference document on the Fortinet support site.

I now need a second trigger for when I disconnect from the network. The Event ID for that is “client-leave-wtp.” Setup the trigger using the same basic structure as the connect trigger.

I then setup the same triggers for my partners phone using their MAC address in the stamac field.

Create the Action

Switch to the Action tab and create a new action of type Webhook

The specifics of the Webhook configuration will depend on how you configure the webhook plugin in Homebridge. Note that the configuration below is wildly insecure. I would recommend setting up HTTPS and authentication for your Webhooks.

4 actions were created 2 for each iPhone to send the Webhook that marks the sensor occupied or unoccupied

Create the Stich

Switch to the stitch tab and create a new stitch that ties together the matching action and trigger that you created above

Configure HomeKit

I’m now successfully informing Homebridge if either of us is connected or disconnected from Wifi. Now I need to link the lights to that action. The built in HomeKit automation allows me to trigger a scene based on occupancy. The problem with this is that each of our phones are different occupancy sensors. The built in automation editor only allows a single condition to fire the automation. I want the lights to come on if either of us is home but not turn off unless both of us are gone.

Once again we need some third party software to create the automation. I use Controller for HomeKit which brings the ability to add additional logic to HomeKit automations. Controller is a paid app for some of the advanced features. I’m told that the Eve app can do similar for free but I haven’t tested that.

I used Controller to create three automations. The first turns the life on if I am on the network OR my partner is on the network

Now I need to insert the logic that confirms both Phones are off the network before turning off the lights. I need two automations for that. The reason is that if I combined my leaving or my partner leaving into an OR for the trigger it would still turn off when either of us left. I can add the AND option to only turn it off if someone leaves and the other person has already left. So, I need two to cover the scenario where I drop off the network first or my partner does. The IF is when the person goes off the network and the AND is if the other persons occupancy sensor is unoccupied.

Linux ARP Table Overflow

TL;DR – The sysdig utility can help you find the process sending ARP requests.

I recently ran into a problem with my “core” server. Its a trusty little Ubuntu 22.04.1 box that wears a lot of hats. In order to combine all of the functions it requires it has some more exotic network setups such as client VPNs, policy based routing, IPv6 an multiple wired and wireless interfaces. Linux is incredibly powerful but sometimes getting advanced features to work using the distro’s native tools is tough… but that’s not the point here.

I woke up this morning to DNS resolution being extremely slow, web pages for my monitoring system not fully loading, the general signs that something was up.

Taking a look at /var/log/syslog I found this message repeated over and over again:

neighbour: arp_cache: neighbor table overflow!

A quick look at the table with arp -a showed 1000’s of incomplete entries like the ones below

? (172.18.0.8) at <incomplete> on br-55a80fab0a50
? (172.18.1.192) at <incomplete> on br-55a80fab0a50
? (172.18.2.152) at <incomplete> on br-55a80fab0a50
? (192.168.1.191) at <incomplete> on eno1
? (172.18.0.51) at <incomplete> on br-55a80fab0a50
? (172.18.1.203) at <incomplete> on br-55a80fab0a50
? (172.18.2.131) at <incomplete> on br-55a80fab0a50
? (192.168.1.170) at <incomplete> on eno1
? (172.18.0.62) at <incomplete> on br-55a80fab0a50
? (172.18.1.246) at <incomplete> on br-55a80fab0a50
? (172.18.2.142) at <incomplete> on br-55a80fab0a50
? (192.168.1.213) at <incomplete> on eno1
? (172.18.0.41) at <incomplete> on br-55a80fab0a50
? (172.18.1.225) at <incomplete> on br-55a80fab0a50
? (172.18.2.185) at <incomplete> on br-55a80fab0a50
? (192.168.1.192) at <incomplete> on eno1
? (172.18.0.84) at <incomplete> on br-55a80fab0a50
? (172.18.1.236) at <incomplete> on br-55a80fab0a50
? (172.18.2.164) at <incomplete> on br-55a80fab0a50
? (192.168.1.203) at <incomplete> on eno1
? (172.18.0.95) at <incomplete> on br-55a80fab0a50
? (172.18.1.23) at <incomplete> on br-55a80fab0a50
? (172.18.2.175) at <incomplete> on br-55a80fab0a50
? (192.168.1.246) at <incomplete> on eno1
? (172.18.0.74) at <incomplete> on br-55a80fab0a50
? (172.18.1.2) at <incomplete> on br-55a80fab0a50
? (172.18.2.218) at <incomplete> on br-55a80fab0a50
? (192.168.1.225) at <incomplete> on eno1

This is obviously the symptom of SOMETHING scanning the network for usable IP’s. Because my docker virtual interfaces are all /16’s that’s 65k of addresses per docker network (i have 4) that its blasting all over the place.

You CAN clear the entire arp table with

ip -s -s neigh flush all

You can only delete individual entries with the standard arp command

Doesn’t matter however, flushing the table just filled it up with more entries as fast as they could be deleted.

Remember I said this box wears a lot of hats? That means there are a lot of places where this traffic could be coming from. Since this was only ARP traffic, and incomplete at that, I couldn’t use tcpdump or lsof (despite trying) to track down the source.

I eventually found this incredible article which sent me down the right path with a utility I had never heard of: sysdig

Sysdig was installed with standard apt commands but had some interesting post-installation instructions. It requires a kernel module that must be loaded at boot and must be properly signed in the UEFI world to not throw boot problems.

When you install sysdig it will ask you for a password, you only use this once so its not that critical. After the install is complete, reboot the system and a TUI will appear with options to allow you to install the MOK. Use the password you set above when prompted (it will not display *** or characters on the screen when typing). After the MOK was installed I was able to run this command as root:

sysdig fd.rip=x.x.x.x

x.x.x.x equaled one of the bogus IPs from the incomplete ARP entries.

Sure enough, it showed me the process. In my case it was a Homebridge plugin that creates motion sensors in Apple HomeKit based on the presence (or lack thereof) of a MAC address on your network. On a typical system scanning your local network isn’t that big a deal (tho not ideal) as people tend to run a /24. With all of the docker interfaces I just had too many potential IPs to scan.

My Journey to IPv6: Part 3 – Outbound Firewall

Three is the magic number

In parts 1 and 2 we discussed IPv6 addressing, and connection basics then configured a Fortigate to grab a DHCPv6 PD prefix and distribute it with SLAAC to clients on the inside network. In this episode I will go over the Fortigate firewall and security policy configuration to get your IPv6 traffic out to the Internet.

The illusion of control

In part 1 I discussed how router advertisements are sent and how they are critical to the operation of an IPv6 network. Those messages are sent using the Internet Control Message Protocol version 6 (ICMPv6) protocol; ICMP being best known as the “ping” protocol in IPv4. Ping was not the only message that ICMPv4 could carry but most of the rest of the message formats were not heavily used in real-world environments. That combined with a security hegemony that promoted blocking ICMP at the network edge resulted in a protocol that could not be relied upon across the public Internet. We all survived.

In version 6, ICMP not only supports similar message types to v4 it also incorporates the functions of other v4 protocols such as ARP (now neighbor discovery protocol, NDP) and IGMP (multicast listener query, MLD). Can you imagine running a successful Ethernet network while blocking ARP? Even more (worse?) than that – There is no packet fragmenting in IPv6. If you send a packet that has to be fragmented the response is to notify the sender of the problem and drop the packet. The notification is an ICMPv6 message.

Long and short – ICMP is not optional in IPv6 and should be available end to end between devices connected to the Internet. Put another way: you should allow ICMPv6 to and from the Internet. If you are particularly paranoid/security minded, you could use the firewall to only allow certain IPv6 messages (such as those fragmentation notifications) through but “the IPv6 way” is that ICMPv6 will work from end to end.

NAT? No! No NAT!

In the IPv6 world firewalls go back to their roots and just become firewalls again. We think of firewalls as router/switch/firewall/NAT all in one devices but it’s easy to remember that NAT was an add on and not ideal. It will be reflexive when setting up inside -> WAN rules to turn on SNAT. The first place we go to setup an inbound rule will be to setup a VIP. Neither of these things are true anymore. Use all public IP’s and subnets in your IPv6 policies and leave NAT off.

Gotta keep ’em seperated

Fortinet has steadily moved IPv6 closer and closer to being a first-class citizen on its devices unlike some other manufacturers (I’m looking at you, Cisco Meraki). As of version 7.2.x you can perform the majority of your familiar IPv4 functions using IPv6 right in the web GUI. That said, v4 and v6 are different protocols not just an extension of each other so many commands and functions have a “6” version in the configuration. When viewing firewall policies, you can view v4 or v6 alone or you can see a combined view with both protocols in a single ruleset. You use the drop down in the upper right to select your protocol version view.

Keep this in mind when you are working with IPv6 in the Fortigate, check all configuration screens and CLI stanzas to see if there is a separate “6” version of that function.

Rules of the road

My basic rules are to allow ICMPv6 inbound and allow outbound Internet access. Using “all” in firewall rules should be avoided where possible but this does present a potential issue. DHCPv6 PD prefixes SHOULD be “permanent” to a subscriber and not change or only change in rare instances. Up until this point, however, we have not had to hard code the PD prefix into any firewall objects. Everything has been a variable saying, “use whatever you get from Verizon on ID 5.” Fortigate doesn’t have an address object construct that dynamically updates if the PD prefix changes. You must create a static IPv6 Address (not Address!) object with your PD prefix included.

I’ve rebooted my equipment several times since I setup IPv6 and my prefix remained stable. My IPv4 on FiOS has been remarkably stable as well so I have decent confidence that I won’t have to be changing this all the time, but you never know. They don’t care, they don’t have to; they’re the phone company.

Then I use that newly created object to create an outbound Internet rule

Notice the little 6 on the “all” destination object. Since v4 and v6 are different protocols, they have different “all” objects. You will get an error if you try to my IPv4 and v6 objects in a single policy. The top section is al you need. Don’t. Enable. NAT.

Use the same subnet object to create an inbound rule allowing ICMPv6 traffic from the Internet to your internal network.

Again, I know allowing all ICMPv6 traffic may make you nervous. You have two options:

  • Create custom services matching the ICMPv6 message types you wish to allow or block and craft your rules that way
  • If you have the license, use the IPS profiles to check for anomalous ICMPv6 attacks and traffic that might cause you problems.

I went with option 2 as you can see in the screen shot.

Fore!

You now should have end to end Internet browsing capabilities using native IPv6. In the next chapter I’ll discuss inbound connectivity to servers hosted inside your network.

My Journey to IPv6: Part 2 – Fortigate Address Configuration

How did we get here?

In part 1 of this series I covered some basics about how IPv6 addresses are distributed. In summary we use DHCPv6 PD to find out from an ISP what prefix should be placed on our clients. After that a combination of SLAAC and DHCPv6 result in one (or more) IP address and DNS server combo that gives a client IPv6 connectivity.

As mentioned in the first article I have Verizon FiOS without their router. I use a Fortigate 40F for routing and firewall. My internal network is a flat broadcast domain with wired and wireless clients. My goal is to have those clients automatically assign themselves addresses and get out to the Internet as well as allowing inbound web and media (Plex) service on native IPv6 to servers on the network.

My Fortigate is running FortiOS 7.2.2; the latest and greatest as of this writing. While Fortinet has a long history of IPv6 support, the richness of the feature set and the amount of configuration that can be performed (or even viewed) in the GUI grows with each release. Since this is my home network I have the luxury of no one losing money (or my job) if the network goes down due to a firewall bug so I run the latest firmware. I would not recommend running bleeding edge firmware in a business environment. I only point this out because some of the syntax and screenshots that I have may be different in earlier versions of FortiOS. YMMV.

Grab the delegated prefix from the WAN

UPDATE: I have found that any changes to the DHCP-PD settings on the WAN interface will result in Verizon issuing you a new prefix. My prefix survives a reboot but once i made a change and put it back and i got a new one. Ib my case it was a mistake, i typed “edit 6” intstead of “edit 5” to take a look at the current settings and as soon as the link saw the DHCP-PD ID added to the request (hadn’t removed or touched 5) it gave me a new prefix. Be warned once you have this all working.

Here is the CLI config block from the WAN ethernet interface

You can see the typical DHCP configuration for the IPv4 WAN address and the multiple lines related to IPv6.

set ip6-allowaccess ping

This allows the link local address of the WAN interface to be pinged. Not 1000% sure this is required but the theme in IPv6 is to allow ICMPv6 and not worry about it

set dhcp6-prefix-delegation enable

This is the critical line. It tells the Fortigate to send out a DHCPv6 request for a prefix delegation.

set autoconf enable

This line enables SLAAC for the WAN interface itself. You’ll remember in the first article I talked at length about how WAN interfaces don’t need routable IPs. The reason I know this is that Verizon doesn’t seem to use a standard way of assigning them. There are no router advertisement with routable prefixes and running a stateful DHCPv6 client on the WAN interface (i said DHCPv6 usually doesn’t hand out actual addresses but it CAN) doesn’t result in any offers of an address. It does offer a default route but it will not show in the regular routing table. You can view the link local address of the ISP next hop default route by running

diag ipv6 route list

The dhcp6-iapd-list subsection configures options around the prefix that Verizon is offering.

        config dhcp6-iapd-list
            edit 5
                set prefix-hint ::/56
                set prefix-hint-plt 0
                set prefix-hint-vlt 0
            next

set prefix-hint ::/56

A better word than hint is ask. This is what we are going to ask Verizon to give us. We’re asking for a /56 subnet as that according to my research is the largest size the allocate to residential customers. Its more than enough as a /56 is 256 /64 subnets. We’re only going to use one for now but if we ever wanted to add additional VLAN’s or networks internally we would now have IPv6 space to assign to them.

set prefix-hint-plt 0

set prefix-hint-vlt 0

These two values ask Verizon to lease us the address permanently/perpetually. I dont know if they are actually honored but the less chance of my PD prefix changing the better.

Notice that I am editing position 5 in the list even though there is only one entry. All of the documentation that I found on other implementations had a 1 instead of a 5. I learned that this value is not arbitrary but must match the ID of the prefix in the DHCPv6 message. I assume this is so that one message can contain multiple prefixes. I was able to find the ID that Verizon was sending by renewing the DHCPv6 lease on the WAN interface while running a debug. This value is used several times in the config.

diag debug application dhcp6c -1

Handout SLAAC advertisements on the inside interface

set ip6-mode delegate

This tells the interface to get its own IP from the delegated prefix

set ip6-allowaccess ping

Allow this interface to respond to ping requests

set ip6-send-adv enable

Send router advertisements on this interface

set ip6-other-flag enable

In the advertisements tell clients to get other information (read: DNS servers) from DHCPv6

set ip6-upstream-interface "wan"

Use the delegated prefixes received on the wan interface (you could have multiple WANs) for assigning an IP to this interface.

set ip6-delegated-prefix-iaid 5

This matches the value we used on the WAN configuration and found in the debug

set ip6-subnet ::fff0/64

This indicates how the interface will form its own address. The subnet above is appended to the PD prefix and that is the IP of the inside interface.

        config ip6-delegated-prefix-list
            edit 1
                set upstream-interface "wan"
                set delegated-prefix-iaid 5
                set subnet ::/64
                set rdnss-service delegated
            next
        end

These options indicate what delegated prefix should be used in SLAAC advertisements for clients. The first two lines are self explanatory (match the debug ID). The subnet line tells the client that their subnet is /64 bits in length. The RDNSS line tells the router advertisements to repeat the DNS servers they receive from the ISP in its advertisements. We will configure stateless DHCPv6 for DNS server assignment as most clients will use that but having this doesn’t hurt.

Configure DHCPv6 to assign DNS servers

The DNS servers listed above are OpenDNS publicly available recursive resolvers.

On to part 3

In this part we configured a Fortigate firewall to retrieve an IPv6 prefix from Verizon FiOS and hand them out to clients on the inside network.

My Journey to IPv6: Part 1 – IPv6 Basics

Background

I’ve been an IT infrastructure engineer for more than 20 years. Cut my teeth in the early days of campus L3 switching. I was lucky enough to have one of my first jobs at a public educational institution that owned a PI Class-B. Those were heady days. Like so many others out there, I looked at IPv6 as something I could hopefully avoid until retirement. The inability to reel off an entire IP subnetting scheme for a company from memory was too dear to my heart. But the times they are a changin…. About a week ago while debugging an issue on my home network I discovered that Verizon had enabled IPv6 on my FiOS circuit. I don’t use their router, only the ONT. Instead, I use a Fortigate 40F running FortiOS 7.2.2 as my router and firewall. I host several websites and a media server on my home network. My goal was to move as much traffic as possible to native IPv6 without disrupting the services that were already functional under v4.

Part one of this series covers some of the background on how IPv6 hands out addresses and configuration. Subsequent parts will cover how to configure a Fortigate firewall with IPv6 on Verizon FiOS and some challenges that I overcame with serving up workloads on IPv6.

Stop. Do not pass go. Do not think like its v4.

Many articles that I read along the way started with a statement along the lines of “forget everything you knew about IPv4” or “Get rid of your IPv4 mindset.” In some ways, this is valid advice. Forget NAT, ARP and CIDR its now GUAs, NDP and /64s. In other ways these statements are an example of both why IPv4 sticks around and why IPv6 adoption has been slow (both of those things are independently true) – IPv6 proponents assume some pretty rigid design standards and criteria whereas IPv4 is an amalgamation of features and standards that “make it work.” A lot of “make it work” kludgyness is exactly what IPv6 was intended to fix and it has, but we don’t all work in enterprises or carrier networks with beautifully hierarchical networks and clear boundaries. There are religious debates about IPv6 methodology that would make the crusades look like a casual chat; I’m not going to wade into those debates in this article. Suffice to say – I adopted the network “design” for my IPv6 implementation that was best supported by my equipment, software and “business needs.” It may not be perfect, but it works cleanly enough for me.

If you want the whole truth and nothing but the truth, try Cisco Press. I dramatically oversimplify several topics, jump around without foundation and make assumptions for demonstration purposes. There are many many MANY sites out there that will tell you how to read and shorten an IPv6 address, the history of IPv6 etc etc. I had read a good number of them myself and could speak the vocabulary of IPv6 but it wasn’t untilI dove in, rolled up my sleeves and gave it a shot that I learned what I really needed to know. This series is intended to be some real world advice and guidance from someone who crash coursed their own home network and servers into being IPv6 native.

IPv6 IP Address Assignment

The typical procedure for a home Internet setup would be to enable DHCP, plug in, get your “WAN” IP and move along. DHCPv6 is a thing so similar procedure to get your IPv6 address? Not exactly. There are three main reasons the procedure is different:

  • Your firewall doesn’t need, and may not get, a WAN IP
  • There is no NAT in IPv6 (there is but it’s like Fight Club)
  • DHCPv6 (usually) doesn’t hand out addresses

Wait. Wut?

YOU get a routable IP and YOU get a routable IP….

A primary tenant of IPv4 networking is that your WAN IP is the “gateway” to the Internet. You can’t send traffic to a 192.168/16, 172.16/12 or 10/8 IP across the Internet, only to a routable IP. While there is an IPv6 equivalent to those private address spaces (but using it is one of those religious battles I mentioned above), the RIGHT way to do it is to put a routable IP on every device. That’s right. Every device gets a real, routable IP. Notice that I keep saying routable and not public. That’s because – routability is not a security feature. NAT was invented because we were running out of IP’s not because the world wanted to hide stuff. The hiding stuff was a “bonus” that network and security engineers alike have taken advantage of over the years. Being hidden does not make you safe in fact it can make it worse because you are assuming your lack of visibility is making you safer.

Just because an address is routable doesn’t mean its public. Remember I said I worked at a place with a public class B network? We didn’t NAT. Anything. All of the computers on campus had a real IP address – but that doesn’t mean you could get to them. You still had to traverse the firewall at the edge (well, once we HAD a firewall, that’s for a different post). The same is true for IPv6, everything gets a real IP address that is routable over the Internet; the firewall decides what is allowed to go to and from it. There is no “front door” address that everyone goes through.

Link local addresses for fun and profit

OK fine, so everyone has a public IP then why doesn’t my router have one? It doesn’t need one – bear with me. Have you ever seen a 169 IP on your computer? If so, you have seen what is known as a link local address. In IPv6 these start with fe80::. In IPv4 if you see one of these it pretty much means something is broken. If you DON’T see these in IPv6 then it definitely means something is broken. Link local means just that – it is an address that is local to a given link which in most cases means the ethernet or wireless SSID you are connected to. You can’t send traffic to a 169 IP that is on a network you aren’t directly connected to. If you have a 169 IP as your only IP, your traffic will never leave your local network and you’ll never get to the Internet. So why isn’t it a breakage when you have an fe80:: address and why can my router be on the Internet with only an fe80:: address?

When you send a packet, v4 or v6, the header contains the address of the source and the address of the destination. It does NOT tell you how to get from A to B, that’s what the router is for. The router receives the packet, looks at the destination says “what the next step to get there” and sends it to the next hop. That process continues until it reaches the router with the destination directly attached. The point is – the next step only matters to that router so only that router has to be able to talk to the next step.

Consider the diagram above. The two routers in the middle are ISP transit routers and the client and server are connected to the Internet. The client and server have routable IPs, the routers do not.

Client generates a packet with a destination of 2001:0DBF::1 and its default gateway is fe80::1233 which is on RTR A. Packet reaches RTR A which says “whats the fastest way to get to 2001:0DBF::1?” “Why I’ll fling the packet at fe80::1234 and hope for the best.” BUT BUT BUT! What about the duplicate IP??

No one would ever set their network up this way but I did it to make a point. Link local addresses only have to be unique on a given link. So then how does the system know which of the duplicate addresses to source the traffic from? Another IPv6 wrinkle – when you set a static route to a link local address you have to specify the link (interface) that it should use unlike IPv4 which will derive the interface from the next hop.

So while your “WAN” interface is the one connected to the internet, its really just inside of someone else’s network. The traffic from the client to the server doesn’t need to hit the WAN IP anymore because the server has a routable IP. And so since user/Internet traffic doesn’t have end to end conversations with WAN interfaces and routers (they are just a hop along the way) there is no need to put a routable IP on the WAN interface of the firewall, only on the devices that will actually need end to end Internet communication.

FWIW – This technically isn’t a feature of IPv6, routing is similar enough in IPv4 that you could use private addresses this way but it isn’t nearly as common.

What’s my block?

We know the firewall’s WAN interface wont get an IP but its still the device connected to the ISP so it must be involved in getting a routable IP onto the clients on the network. But what addresses should it hand out? In the IPv4 days we would select a subnet from the RFC 1918 space and we could choose whatever we wanted because the addresses only have to be unique within our own network. Since IPv6 addresses must be globally unique we can’t just select them ourselves the ISP must assign them and then tell us what addresses we’re allowed to use. Verizon FiOS (and many other ISP’s) uses DHCPv6 Prefix Delegation (PD) to inform a router what addresses it should hand out. I mentioned above that in IPv6 DHCP isn’t used to hand out addresses. It can be but that’s not the typical design. Instead, DHCPv6 usually gives you everything OTHER than your IP address and one of those things is what prefix has been delegated to you by your ISP to assign to the clients in your network.

What’s my address?

If DHCPv6 doesn’t tell you what your IP is, what does? In the IPv6 world you build it yourself with some help from your local router. When an IPv6 capable router is connected to a link it sends advertisements and listens for solicitations about the network it routes for. It uses ICMPv6 to send these messages. We usually think of ICMP as ping in the IPv4 world. In IPv6 it takes on a much larger role. When you connect a client to an IPv6 network it listens for the advertisements from the local router. That advertisement says “Here is subnet of the network you are on” and then the client generates its own address in that subnet. This conversation all takes places over fe80:: link local addresses that are generated by running a hash against the MAC address of the interface.

The space between

In IPv6 while addresses are 128 bits and use the same / notation for subnetting as IPv4, there is a rule everyone follows: 64 Bits for the network and 64 bits for this host. The first half of the address is the subnet and the second half is the client itself, a /64 subnet. All subnets are /64s. So taking this example:

2001:0DB8:95fa:e900:0000:0000:0000:ffff/64

  • Network – 2001:0DB8:95fa:e900
  • Host – 0000:0000:0000:ffff

You may have realized by now that this means there can be a lot of hosts in a subnet. 18,446,744,073,709,551,616 to be exact. Play the tape to the end – yes, on a home network with 2 laptops, an iPhone and an Apple TV there will be over 18 quintillion free IP’s in that subnet. That may seem wasteful but its one of the things it’s best just to get zen about if you’re going to work with IPv6.

Putting it together

As a client I have a subnet I know I’m in from a router advertisement and I know I have 64 bits to fill with a (hopefully) unique value to make a full IPv6 address. I mentioned earlier that the fe80:: link local address is generated by hashing the MAC address. A similar hash of the MAC address is tacked on to the end of the subnet in the router advertisement to create the IP that the client assigned to itself. This process, the advertisements, MAC hashing and IP self assignment is called Stateless Address Auto-Configuration or SLAAC. There is a lot more to SLAAC under the hood including checking multiple times for conflict. If you would like that level of detail, check out this excellent article from Network Academy.io

Since the second half of an IPv6 address is based on a known method of hashing a MAC address it is possible to envision how easy it would be to track a given MAC address (and its owner) as it moved from network to network. That would be a serious security and privacy concern. To combat this, modern implementations of SLAAC generate (at least) two addresses. One address is based on the MAC hash, is assigned “permanently” to the interface and is used for general IP communication. An additional private (sometimes called temporary) IPv6 address is generated using a random algorithm. This address is used as the source when browsing the web or performing other activities that the OS determines shouldn’t be tracked with your device. The OS will roll over this address to a new random value on a regular basis.

Whats in a name?

The client now has a routable IP and a link local next hop to get to the Internet. What’s missing? It’s always DNS. The original SLAAC protocol didn’t include a method for distributing DNS servers along with IP information and without DNS the Internet is pretty boring. Re-enter DHCPv6. It is very common to run DHCPv6 along side SLAAC just for distributing DNS servers. There are updates to the SLAAC protocol to allow it to distribute DNS servers but this is the a common configuration. I personally configured both.

Until Next Time

That’s all for part 1… next time I’ll take a look at how to implement the process from this article on a Fortigate firewall with Verizon FiOS.