make_igmpproxy_config.ncd 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. process main {
  2. call("make_igmpproxy_config", {"br0", "eth1", "./igmpproxy.conf.template", "./igmpproxy.conf"});
  3. println("Done.");
  4. exit("0");
  5. }
  6. template make_igmpproxy_config {
  7. alias("_arg0") upstream_iface;
  8. alias("_arg1") downstream_iface;
  9. alias("_arg2") template_file;
  10. alias("_arg3") output_file;
  11. # Make a list of interfaces to add as disabled (upstream and downstream will not be disabled).
  12. var({
  13. "eth0", "eth1", "eth2", "eth3", "eth4", "eth5", "eth6", "eth7", "eth8", "eth9",
  14. "wlan0", "wlan1", "wlan2", "wlan3", "wlan4", "wlan5", "wlan6", "wlan7", "wlan8", "wlan9",
  15. "tap0", "tap1", "tap2", "tap3", "tap4", "tap5", "tap6", "tap7", "tap8", "tap9",
  16. "br0", "br1", "br2", "br3", "br4", "br5", "br6", "br7", "br8", "br9"
  17. }) disabled_ifaces;
  18. # Build replacements for template config.
  19. var({"<UPSTREAM_IFACE>", "<DOWNSTREAM_IFACE>"}) regex;
  20. var({upstream_iface, downstream_iface}) replace;
  21. # Read template config.
  22. file_read(template_file) template_data;
  23. # Perform replacements.
  24. regex_replace(template_data, regex, replace) replaced_data;
  25. # Build string value from replaced_data, to which we will append
  26. # configuration for disabled interfaces.
  27. value(replaced_data) output_data;
  28. # Build disabled strings.
  29. Foreach (disabled_ifaces As iface) {
  30. # Determine if the interface is disabled.
  31. val_equal(iface, upstream_iface) is_up;
  32. val_equal(iface, downstream_iface) is_down;
  33. or(is_up, is_down) is_not_disabled;
  34. not(is_not_disabled) is_disabled;
  35. # If it's disabled, append to the configuration file.
  36. If (is_disabled) {
  37. concat("phyint ", iface, " disabled\n") str;
  38. output_data->append(str);
  39. };
  40. };
  41. # Write config.
  42. file_write(output_file, output_data);
  43. }