37 |
37 |
38 cfg.CONF.register_opts(OPTS) |
38 cfg.CONF.register_opts(OPTS) |
39 |
39 |
40 NDP_SMF_FMRI = 'svc:/network/routing/ndp:default' |
40 NDP_SMF_FMRI = 'svc:/network/routing/ndp:default' |
41 |
41 |
42 CONFIG_TEMPLATE = jinja2.Template("""if {{ interface_name }} \ |
42 # The configuration file for ndpd daemon expects all the 'key value' to be |
43 AdvSendAdvertisements on \ |
43 # on the same line as that of the interface. For example: |
44 MinRtrAdvInterval 3 \ |
44 # |
45 MaxRtrAdvInterval 10 \ |
45 # if net0 AdvSendAdvertisements on MinRtrAdvInterval 3 MaxRtrAdvInterval 10 |
46 {% if ra_mode == constants.DHCPV6_STATELESS %} |
46 # prefix 3234234 net0 AdvOnLinkFlag on AdvAutonomousFlag on |
47 AdvOtherConfigFlag on \ |
47 CONFIG_TEMPLATE = jinja2.Template( |
48 {% endif %} |
48 """if {{ interface_name }} """ |
49 |
49 """ AdvSendAdvertisements on MinRtrAdvInterval 3 MaxRtrAdvInterval 10 """ |
50 {% if ra_mode == constants.DHCPV6_STATEFUL %} |
50 """ {% if ra_mode == constants.DHCPV6_STATELESS %} """ |
51 AdvManagedFlag on |
51 """ AdvOtherConfigFlag on """ |
52 {% endif %} |
52 """ {% endif %} """ |
53 |
53 """ {% if ra_mode == constants.DHCPV6_STATEFUL %} """ |
54 {% if ra_mode in (constants.IPV6_SLAAC, constants.DHCPV6_STATELESS) %} |
54 """ AdvManagedFlag on """ |
55 prefix {{ prefix }} {{ interface_name }} \ |
55 """ {% endif %} """ |
56 AdvOnLinkFlag on \ |
56 """ {% if ra_mode in (constants.IPV6_SLAAC, """ |
57 AdvAutonomousFlag on |
57 """ constants.DHCPV6_STATELESS) %} """ |
58 {% endif %} |
58 """\nprefix {{ prefix }} {{ interface_name }} """ |
59 """) |
59 """ AdvOnLinkFlag on AdvAutonomousFlag on """ |
|
60 """ {% endif %} """) |
60 |
61 |
61 |
62 |
62 def _generate_ndpd_conf(router_id, router_ports, dev_name_helper): |
63 def _generate_ndpd_conf(router_id, router_ports, dev_name_helper): |
63 ndpd_conf = utils.get_conf_file_name(cfg.CONF.ra_confs, router_id, |
64 ndpd_conf = utils.get_conf_file_name(cfg.CONF.ra_confs, router_id, |
64 'ndpd.conf', True) |
65 'ndpd.conf', True) |
66 for p in router_ports: |
67 for p in router_ports: |
67 prefix = p['subnet']['cidr'] |
68 prefix = p['subnet']['cidr'] |
68 if netaddr.IPNetwork(prefix).version == 6: |
69 if netaddr.IPNetwork(prefix).version == 6: |
69 interface_name = dev_name_helper(p['id']) |
70 interface_name = dev_name_helper(p['id']) |
70 ra_mode = p['subnet']['ipv6_ra_mode'] |
71 ra_mode = p['subnet']['ipv6_ra_mode'] |
71 buf.write('%s' % CONFIG_TEMPLATE.render( |
72 buf.write('%s\n' % CONFIG_TEMPLATE.render( |
72 ra_mode=ra_mode, |
73 ra_mode=ra_mode, |
73 interface_name=interface_name, |
74 interface_name=interface_name, |
74 prefix=prefix, |
75 prefix=prefix, |
75 constants=constants)) |
76 constants=constants)) |
76 |
77 |
79 |
80 |
80 |
81 |
81 def _refresh_ndpd(ndpd_conf): |
82 def _refresh_ndpd(ndpd_conf): |
82 cmd = ['/usr/sbin/svccfg', '-s', NDP_SMF_FMRI, 'setprop', |
83 cmd = ['/usr/sbin/svccfg', '-s', NDP_SMF_FMRI, 'setprop', |
83 'routing/config_file', '=', ndpd_conf] |
84 'routing/config_file', '=', ndpd_conf] |
|
85 utils.execute(cmd) |
|
86 # this is needed to reflect the routing/config_file property |
|
87 # in svcprop output |
|
88 cmd = ['/usr/sbin/svccfg', '-s', NDP_SMF_FMRI, 'refresh'] |
84 utils.execute(cmd) |
89 utils.execute(cmd) |
85 # ndpd SMF service doesn't support refresh method, so we |
90 # ndpd SMF service doesn't support refresh method, so we |
86 # need to restart |
91 # need to restart |
87 cmd = ['/usr/sbin/svcadm', 'restart', NDP_SMF_FMRI] |
92 cmd = ['/usr/sbin/svcadm', 'restart', NDP_SMF_FMRI] |
88 utils.execute(cmd) |
93 utils.execute(cmd) |