Skip to content

logic in routes/rules templates for multiple devices #8

Description

@johanek

Hi,

I have been trying to use this module to configure iproute2 for routing traffic back on the NIC it was received on, i.e. as documented in http://lartc.org/howto/lartc.rpdb.multiple-links.html

I am using Ubuntu 14.04

My hiera config:

iproute2::rt_tables_hash:
  10: eth0
  11: eth1

iproute2::routes_hash:
  -
    network: 10.32.160.0/23
    gateway: 10.32.160.1
    dev: eth0
    src: 10.32.160.210
    table: eth0
  -
    network: 10.32.162.0/23
    gateway: 10.32.162.1
    dev: eth1
    src: 10.32.162.210
    table: eth1

iproute2::rules_hash:
  -
    from: 10.32.160.210
    table: eth0
    dev: eth0
  -
    from: 10.32.162.210
    table: eth1
    dev: eth1

This produces the following if-up.d script:

#!/bin/sh
###
### File managed by Puppet
###

[ "$IFACE" == "eth0" ] || exit 0

/sbin/ip route add 10.32.160.0/23 via 10.32.160.1 dev eth0 src 10.32.160.210 table eth0

[ "$IFACE" == "eth1" ] || exit 0

/sbin/ip route add 10.32.162.0/23 via 10.32.162.1 dev eth1 src 10.32.162.210 table eth1

The config for eth1 is never going to get applied because the first condition will only ever allow eth0 to be configured.

I made a change that wraps each ip route command in an if statement, you can see it here: https://github.com/sohonet/puppet-iproute2/pull/1/files

I also needed to run ip route add default via 10.32.160.1 table eth0 as well, rather than having via 10.32.160.1 in the original route.

Additionally, I found the rules were being applied multiple times, so I wrapped them in an if...then conditional too.

I haven't raised a PR for this, as these changes work for my use case, but I'm not sure if they would break existing functionality.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions