container_init 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. #!/bin/sh /etc/rc.common
  2. # Copyright (C) 2018 Mikael Magnusson
  3. START=15
  4. log_output() {
  5. logger -t container_init "$@"
  6. }
  7. boot() {
  8. # Only execute for lxc containers
  9. if [ "$container" != "lxc" ]; then
  10. exit 0
  11. fi
  12. local disable_ipv6="$(uci_get firewall @defaults[0] disable_ipv6 false)"
  13. case "$disable_ipv6" in
  14. '0'|'no'|'off'|'false'|'disabled') disable_ipv6=false ;;
  15. '1'|'yes'|'on'|'true'|'enabled') disable_ipv6=true ;;
  16. esac
  17. tables='filter nat mangle raw'
  18. res=0
  19. for table in $tables; do
  20. iptables -n -t $table -L >/dev/null 2>/dev/null
  21. if ! grep $table /proc/net/ip_tables_names >/dev/null; then
  22. log_output -p daemon.crit "ip $table load failed"
  23. res=1
  24. fi
  25. if [ "$disable_ipv6" = "false" ]; then
  26. ip6tables -n -t $table -L >/dev/null 2>/dev/null
  27. if ! grep $table /proc/net/ip6_tables_names >/dev/null; then
  28. log_output -p daemon.crit "ip6 $table load failed"
  29. res=1
  30. fi
  31. fi
  32. done
  33. if [ "$res" == "0" ]; then
  34. if [ "$disable_ipv6" = "false" ]; then
  35. log_output -p daemon.info "ip and ip6 tables loaded successfully"
  36. else
  37. log_output -p daemon.info "ip tables loaded successfully"
  38. fi
  39. fi
  40. if [ ! -e /lib/modules/$(uname -r) ]; then
  41. local modulesdir=$(basename $(dirname $(opkg files kmod-ipt-core|grep "/lib/modules/[0-9].*"|head -1)))
  42. ln -s $modulesdir /lib/modules/$(uname -r)
  43. fi
  44. exit $res
  45. }