cocoon-net

Embedded DHCP Server

cocoon-net daemon runs its own DHCPv4 server (dhcp/, built on insomniacslk/dhcp) on the cni0 bridge instead of depending on an external DHCP server. VMs plug into cni0 via the CNI bridge plugin (see Architecture) and obtain their VPC-routable IP directly from this server.

Lease lifecycle

Dynamic host routes

On every lease event the daemon updates the host’s routing table so the new IP is immediately reachable:

This keeps the kernel routing table minimal (only currently-leased IPs are routed) and means a VM’s IP is reachable within the VPC as soon as it has a lease, with no static route provisioning per VM.

Traffic isolation

DHCP hands every VM a VPC-routable IP, so cocoon-net also enforces isolation between VMs at two layers:

Same-node VM-to-VM and anti-spoofing are handled at L2 by the CNI bridge plugin, baked into the generated conflist:

Cross-node VM-to-VM and external ranges are blocked at L3 via --drop-cidr:

Return traffic and internet egress are unaffected. DROP rules are tagged cocoon-net-drop, so teardown removes exactly them.

sudo cocoon-net init \
  --platform gke --node-name cocoon-pool \
  --subnet 172.22.0.0/24 --pool-size 140 \
  --drop-cidr 172.22.0.0/16

Traffic to the node’s own address (e.g. a kubelet bound on the cni0 gateway IP) is delivered via INPUT, not FORWARD, so these flags do not cover it – restrict those separately (host INPUT rule or bind off cni0).

Running the daemon

sudo cocoon-net daemon

The daemon loads the pool from pool.json, re-applies node setup (sysctl, bridge, iptables, CNI conflist – pass --skip-iptables to omit the iptables step), and starts the DHCP server described above. See Installation for the systemd unit.

On cocoon-net teardown, both pool.json and the DHCP leases.json are removed.