]> git.ipfire.org Git - people/ms/network.git/blobdiff - src/network
network: Show when a PHY supports ACS
[people/ms/network.git] / src / network
index daaf12266266dee7d57e7e9c46db63b62122f125..3535133d586434695fcde2689da6bd68734559e7 100644 (file)
@@ -39,13 +39,13 @@ done
 network_settings_read
 
 cli_settings() {
-       if cli_help_requested $@; then
+       if cli_help_requested "$@"; then
                cli_show_man network-settings
                exit ${EXIT_OK}
        fi
 
        if [ -n "${1}" ]; then
-               network_settings_set $@
+               network_settings_set "$@"
                network_settings_write
        else
                network_settings_print
@@ -53,7 +53,7 @@ cli_settings() {
 }
 
 cli_device() {
-       if cli_help_requested $@; then
+       if cli_help_requested "$@"; then
                cli_show_man network-device
                exit ${EXIT_OK}
        fi
@@ -63,7 +63,7 @@ cli_device() {
 
        case "${action}" in
                list)
-                       cli_device_list $@
+                       cli_device_list "$@"
                        ;;
                *)
                        local device="${action}"
@@ -79,22 +79,22 @@ cli_device() {
 
                        case "${action}" in
                                discover)
-                                       cli_device_discover ${device} $@
+                                       cli_device_discover ${device} "$@"
                                        ;;
                                identify)
-                                       device_identify "${device}" $@
+                                       device_identify "${device}" "$@"
                                        ;;
                                monitor)
-                                       cli_device_monitor "${device}" $@
+                                       cli_device_monitor "${device}" "$@"
                                        ;;
                                status)
                                        cli_device_status ${device}
                                        ;;
                                unlock)
-                                       cli_device_serial_unlock ${device} $@
+                                       cli_device_serial_unlock ${device} "$@"
                                        ;;
                                ussd)
-                                       cli_device_send_ussd_command "${device}" $@
+                                       cli_device_send_ussd_command "${device}" "$@"
                                        ;;
                                *)
                                        cli_show_man network-device
@@ -148,6 +148,12 @@ cli_device_status() {
        cli_print_fmt1 1 "Status"       "${status}"
        cli_print_fmt1 1 "Type"         "${type}"
 
+       # Print the driver name
+       local driver="$(device_get_driver "${device}")"
+       if isset driver; then
+               cli_print_fmt1 1 "Driver" "${driver}"
+       fi
+
        # Ethernet-compatible?
        device_is_ethernet_compatible "${device}" &>/dev/null
        cli_print_fmt1 1 "Ethernet-compatible" "$(cli_print_bool $?)"
@@ -251,6 +257,13 @@ cli_device_status_phy() {
 
        local address="$(phy_get_address "${phy}")"
        cli_print_fmt1 1 "Address" "${address}"
+
+       # Show kernel module
+       local driver="$(phy_get_driver "${phy}")"
+       if isset driver; then
+               cli_print_fmt1 1 "Driver" "${driver}"
+       fi
+
        cli_space
 
        local devices="$(phy_get_devices "${phy}")"
@@ -264,6 +277,15 @@ cli_device_status_phy() {
                cli_space
        fi
 
+       cli_headline 2 "Features"
+
+       cli_print_fmt1 2 "Automatic Channel Selection" \
+               "$(phy_supports_acs "${phy}" && print "Supported" || print "Not Supported")"
+       cli_print_fmt1 2 "DFS" \
+               "$(phy_supports_dfs "${phy}" && print "Supported" || print "Not Supported")"
+
+       cli_space
+
        return ${EXIT_OK}
 }
 
@@ -339,7 +361,7 @@ cli_device_discover() {
 }
 
 cli_device_serial_unlock() {
-       if cli_help_requested $@; then
+       if cli_help_requested "$@"; then
                cli_show_man network-device
                exit ${EXIT_OK}
        fi
@@ -482,7 +504,7 @@ cli_device_list() {
 }
 
 cli_hostname() {
-       if cli_help_requested $@; then
+       if cli_help_requested "$@"; then
                cli_show_man network
                exit ${EXIT_OK}
        fi
@@ -501,7 +523,7 @@ cli_hostname() {
 }
 
 cli_port() {
-       if cli_help_requested $@; then
+       if cli_help_requested "$@"; then
                cli_show_man network-port
                exit ${EXIT_OK}
        fi
@@ -516,13 +538,13 @@ cli_port() {
 
                case "${action}" in
                        edit|create|remove|up|down|status|identify)
-                               port_${action} "${port}" $@
+                               port_${action} "${port}" "$@"
                                ;;
                        color)
-                               color_cli "port" "${port}" $@
+                               color_cli "port" "${port}" "$@"
                                ;;
                        description)
-                               description_cli "port" "${port}" $@
+                               description_cli "port" "${port}" "$@"
                                ;;
                        *)
                                error "Unrecognized argument: ${action}"
@@ -535,7 +557,7 @@ cli_port() {
 
                case "${action}" in
                        new|destroy)
-                               port_${action} $@
+                               port_${action} "$@"
                                ;;
                        *)
                                error "Unrecognized argument: ${action}"
@@ -546,7 +568,7 @@ cli_port() {
 }
 
 cli_zone() {
-       if cli_help_requested $@; then
+       if cli_help_requested "$@"; then
                cli_show_man network-zone
                exit ${EXIT_OK}
        fi
@@ -574,19 +596,19 @@ cli_zone() {
 
                case "${action}" in
                        port)
-                               cli_zone_port "${zone}" $@
+                               cli_zone_port "${zone}" "$@"
                                ;;
                        rename)
-                               cli_zone_rename "${zone}" $@
+                               cli_zone_rename "${zone}" "$@"
                                ;;
                        config|disable|down|edit|enable|identify|status|up)
-                               zone_${action} ${zone} $@
+                               zone_${action} ${zone} "$@"
                                ;;
                        color)
-                               color_cli "zone" "${zone}" $@
+                               color_cli "zone" "${zone}" "$@"
                                ;;
                        description)
-                               description_cli "zone" ${zone} $@
+                               description_cli "zone" ${zone} "$@"
                                ;;
                        *)
                                error "Unrecognized argument: ${action}"
@@ -600,10 +622,10 @@ cli_zone() {
 
                case "${action}" in
                        new)
-                               cli_zone_new $@
+                               cli_zone_new "$@"
                                ;;
                        destroy)
-                               cli_zone_destroy $@
+                               cli_zone_destroy "$@"
                                ;;
                        ""|*)
                                if [ -n "${action}" ]; then
@@ -619,39 +641,37 @@ cli_zone() {
 }
 
 cli_zone_new() {
-       if cli_help_requested $@ || [ $# -lt 2 ]; then
+       if cli_help_requested "$@" || [ $# -lt 2 ]; then
                cli_show_man network-zone-new
                exit ${EXIT_OK}
        fi
 
-       zone_new $@
+       zone_new "$@"
 }
 
 # Removes a zone either immediately, if it is currently down,
 # or adds a tag that the removal will be done when the zone
 # is brought down the next time.
 cli_zone_destroy() {
-       if cli_help_requested $@; then
+       if cli_help_requested "$@"; then
                cli_show_man network-zone
                exit ${EXIT_OK}
        fi
 
        local zone="${1}"
-       assert zone_exists "${zone}"
 
-       if zone_is_up ${zone}; then
-               echo "Zone '${zone}' is up and will be removed when it goes down the next time."
-               zone_destroy "${zone}"
-       else
-               echo "Removing zone '${zone}' now..."
-               zone_destroy_now "${zone}"
+       # Check if the zone exists
+       if ! zone_exists "${zone}"; then
+               error "Zone '${zone}' does not exist"
+               return ${EXIT_ERROR}
        fi
 
-       exit ${EXIT_OK}
+       echo "Removing zone '${zone}'..."
+       zone_destroy "${zone}" || exit $?
 }
 
 cli_zone_port() {
-       if cli_help_requested $@; then
+       if cli_help_requested "$@"; then
                cli_show_man network-zone-port
                exit ${EXIT_OK}
        fi
@@ -666,7 +686,7 @@ cli_zone_port() {
 
                case "${action}" in
                        edit)
-                               zone_port_edit "${zone}" "${port}" $@
+                               zone_port_edit "${zone}" "${port}" "$@"
                                ;;
                        *)
                                error "Unrecognised argument: ${action}"
@@ -679,10 +699,10 @@ cli_zone_port() {
 
                case "${action}" in
                        attach)
-                               zone_port_attach "${zone}" $@
+                               zone_port_attach "${zone}" "$@"
                                ;;
                        detach)
-                               zone_port_detach "${zone}" $@
+                               zone_port_detach "${zone}" "$@"
                                ;;
                        *)
                                error "Unrecognised argument: ${action}"
@@ -695,7 +715,7 @@ cli_zone_port() {
 }
 
 cli_zone_rename() {
-       if cli_help_requested $@; then
+       if cli_help_requested "$@"; then
                cli_show_man network-zone
                exit ${EXIT_OK}
        fi
@@ -720,12 +740,6 @@ cli_zone_rename() {
                exit ${EXIT_ERROR}
        fi
 
-       # Destroyed zones cannot be renamed
-       if zone_has_destroy_tag "${zone}"; then
-               error "Zone ${zone} is about to be destroyed and cannot be renamed"
-               exit ${EXIT_ERROR}
-       fi
-
        # Check if a zone with the new name already exists
        if zone_exists "${name}"; then
                error "Zone ${name} already exists"
@@ -745,7 +759,7 @@ cli_list_hooks() {
        local type=${1}
        shift
 
-       if cli_help_requested $@; then
+       if cli_help_requested "$@"; then
                cli_show_man network-zone
                exit ${EXIT_OK}
        fi
@@ -765,7 +779,7 @@ cli_dhcpd() {
        local proto=${1}
        shift
 
-       if cli_help_requested $@; then
+       if cli_help_requested "$@"; then
                cli_show_man network-dhcp
                exit ${EXIT_OK}
        fi
@@ -775,7 +789,7 @@ cli_dhcpd() {
 
        case "${action}" in
                edit)
-                       dhcpd_edit ${proto} $@
+                       dhcpd_edit ${proto} "$@"
                        ;;
                start)
                        dhcpd_start ${proto}
@@ -793,10 +807,10 @@ cli_dhcpd() {
                        dhcpd_reload ${proto}
                        ;;
                subnet)
-                       cli_dhcpd_subnet ${proto} $@
+                       cli_dhcpd_subnet ${proto} "$@"
                        ;;
                show|"")
-                       cli_dhcpd_show ${proto} $@
+                       cli_dhcpd_show ${proto} "$@"
                        ;;
                *)
                        error "Unrecognized action: ${action}"
@@ -885,7 +899,7 @@ cli_dhcpd_subnet() {
        local proto=${1}
        shift
 
-       if cli_help_requested $@; then
+       if cli_help_requested "$@"; then
                cli_show_man network-dhcp-subnet
                exit ${EXIT_OK}
        fi
@@ -895,10 +909,10 @@ cli_dhcpd_subnet() {
 
        case "${action}" in
                new)
-                       dhcpd_subnet_new ${proto} $@
+                       dhcpd_subnet_new ${proto} "$@"
                        ;;
                remove)
-                       dhcpd_subnet_remove ${proto} $@
+                       dhcpd_subnet_remove ${proto} "$@"
                        ;;
                *:*/*|*.*.*.*/*)
                        local subnet=${action}
@@ -914,7 +928,7 @@ cli_dhcpd_subnet() {
 
                        case "${action}" in
                                edit)
-                                       dhcpd_subnet_edit ${proto} ${subnet} $@
+                                       dhcpd_subnet_edit ${proto} ${subnet} "$@"
                                        local ret=$?
 
                                        if [ ${ret} -eq ${EXIT_OK} ]; then
@@ -923,15 +937,15 @@ cli_dhcpd_subnet() {
                                        exit ${ret}
                                        ;;
                                range)
-                                       cli_dhcpd_subnet_range ${proto} ${subnet} $@
+                                       cli_dhcpd_subnet_range ${proto} ${subnet} "$@"
                                        exit $?
                                        ;;
                                show)
-                                       cli_dhcpd_subnet_show ${proto} ${subnet} $@
+                                       cli_dhcpd_subnet_show ${proto} ${subnet} "$@"
                                        exit $?
                                        ;;
                                options)
-                                       cli_dhcpd_subnet_options ${proto} ${subnet} $@
+                                       cli_dhcpd_subnet_options ${proto} ${subnet} "$@"
                                        exit $?
                                        ;;
                                *)
@@ -968,10 +982,10 @@ cli_dhcpd_subnet_range() {
 
        case "${action}" in
                new)
-                       dhcpd_subnet_range_new ${proto} ${subnet} $@ || exit ${EXIT_ERROR}
+                       dhcpd_subnet_range_new ${proto} ${subnet} "$@" || exit ${EXIT_ERROR}
                        ;;
                remove)
-                       dhcpd_subnet_range_remove ${proto} ${subnet} $@ || exit ${EXIT_ERROR}
+                       dhcpd_subnet_range_remove ${proto} ${subnet} "$@" || exit ${EXIT_ERROR}
                        ;;
                *)
                        error "Unrecognized action: ${action}"
@@ -1040,7 +1054,7 @@ cli_dhcpd_subnet_show() {
 }
 
 cli_dhcpd_subnet_options() {
-       assert [ $# -eq 2 ]
+       assert [ $# -ge 2 ]
 
        local proto=${1}
        local subnet=${2}
@@ -1050,20 +1064,21 @@ cli_dhcpd_subnet_options() {
                case "${1}" in
                        *=*)
                                key=$(cli_get_key ${1})
-                               val=$(cli_get_val ${1})
+                               val=$(cli_get_val "${1}")
 
                                dhcpd_subnet_option_set ${proto} ${subnet} ${key} ${val}
                esac
+               shift
        done
 }
 
 cli_start() {
-       if cli_help_requested $@; then
+       if cli_help_requested "$@"; then
                cli_show_man network
                exit ${EXIT_OK}
        fi
 
-       local zones=$(zones_get $@)
+       local zones=$(zones_get "$@")
 
        local zone
        for zone in ${zones}; do
@@ -1074,12 +1089,12 @@ cli_start() {
 }
 
 cli_stop() {
-       if cli_help_requested $@; then
+       if cli_help_requested "$@"; then
                cli_show_man network
                exit ${EXIT_OK}
        fi
 
-       local zones=$(zones_get $@)
+       local zones=$(zones_get "$@")
 
        local zone
        for zone in ${zones}; do
@@ -1090,21 +1105,21 @@ cli_stop() {
 }
 
 cli_restart() {
-       if cli_help_requested $@; then
+       if cli_help_requested "$@"; then
                cli_show_man network
                exit ${EXIT_OK}
        fi
 
-       cli_stop $@
+       cli_stop "$@"
 
        # Give the system some time to calm down
        sleep ${TIMEOUT_RESTART}
 
-       cli_start $@
+       cli_start "$@"
 }
 
 cli_status() {
-       if cli_help_requested $@; then
+       if cli_help_requested "$@"; then
                cli_show_man network
                exit ${EXIT_OK}
        fi
@@ -1115,11 +1130,40 @@ cli_status() {
        local log_disable_stdout=${LOG_DISABLE_STDOUT}
        LOG_DISABLE_STDOUT="true"
 
-       local zones=$(zones_get $@)
+       local arguments=( $@ )
 
-       local zone
-       for zone in ${zones}; do
-               zone_status ${zone}
+       # Show all zones when no arguments are given
+       if ! isset arguments; then
+               local zone
+               for zone in $(zones_get_all); do
+                       zone_status "${zone}"
+               done
+
+               return ${EXIT_OK}
+       fi
+
+       local arg
+       for arg in ${arguments[@]}; do
+               # Is this a zone?
+               if zone_exists "${arg}"; then
+                       zone_status "${arg}"
+
+               # Is this a port?
+               elif port_exists "${arg}"; then
+                       port_status "${arg}"
+
+               # Is this a PHY?
+               elif phy_exists "${arg}"; then
+                       cli_device_status "${arg}"
+
+               # Is this a device?
+               elif device_exists "${arg}"; then
+                       cli_device_status "${arg}"
+
+               # Unknown argument
+               else
+                       error "Unknown argument: ${arg}"
+               fi
        done
 
        # Reset logging.
@@ -1127,7 +1171,7 @@ cli_status() {
 }
 
 cli_reset() {
-       if cli_help_requested $@; then
+       if cli_help_requested "$@"; then
                cli_show_man network
                exit ${EXIT_OK}
        fi
@@ -1153,21 +1197,41 @@ cli_reset() {
                fi
        fi
 
+       # Destroy all IPsec VPN connections
+       local connection
+       for connection in $(ipsec_list_connections); do
+               ipsec_connection_destroy "${connection}"
+       done
+
+       local pool
+       for pool in $(ipsec_list_pools); do
+               ipsec_pool_destroy "${pool}"
+       done
+
+       # Stop strongswan
+       ipsec_strongswan_autostart
+
+       # Destroy all user-defined security policies
+       local secpol
+       for secpol in $(vpn_security_policies_list_user); do
+               vpn_security_policies_destroy "${secpol}"
+       done
+
        local zone
-       for zone in $(zones_get --all); do
-               zone_destroy_now "${zone}"
+       for zone in $(zones_get_all); do
+               zone_destroy "${zone}"
        done
 
        local port
-       for port in $(ports_get --all); do
+       for port in $(ports_get_all); do
                port_destroy "${port}"
        done
 
        # Flush all DNS servers.
        dns_server_flush
 
-       # Re-run the initialization functions
-       init_run
+       # Trigger udev to re-add all physical network devices
+       cmd_quiet udevadm trigger --action=add --subsystem-match=net
 
        exit ${EXIT_OK}
 }
@@ -1209,7 +1273,7 @@ cli_help() {
 }
 
 cli_dns_server() {
-       if cli_help_requested $@; then
+       if cli_help_requested "$@"; then
                cli_show_man network-dns-server
                exit ${EXIT_OK}
        fi
@@ -1271,23 +1335,26 @@ cli_raw() {
                db-dump)
                        db_dump
                        ;;
+               device-get-by-mac-address)
+                       device_get_by_mac_address "$@"
+                       ;;
                ipsec-connection-exists)
-                       ipsec_connection_exists $@
+                       ipsec_connection_exists "$@"
                        ;;
                list-devices)
                        device_list
                        ;;
                list-dhcpd-ranges-of-subnet)
-                       dhcpd_subnet_range_list $@
+                       dhcpd_subnet_range_list "$@"
                        ;;
                list-dhcpd-settings)
-                       dhcpd_global_settings_list $@
+                       dhcpd_global_settings_list "$@"
                        ;;
                list-dhcpd-subnets)
-                       dhcpd_subnet_list $@
+                       dhcpd_subnet_list "$@"
                        ;;
                list-dhcpd-subnet-options)
-                       dhcpd_subnet_options_list $@
+                       dhcpd_subnet_options_list "$@"
                        ;;
                list-dns-servers)
                        dns_server_list
@@ -1296,7 +1363,7 @@ cli_raw() {
                        port_list_free
                        ;;
                list-hooks)
-                       hook_list $@
+                       hook_list "$@"
                        ;;
                list-ipsec-connections)
                        ipsec_list_connections
@@ -1305,7 +1372,10 @@ cli_raw() {
                        port_list
                        ;;
                list-ports-of-zone)
-                       zone_get_ports $@
+                       zone_get_ports "$@"
+                       ;;
+               list-vpn-security-policies-all)
+                       vpn_security_policies_list_all
                        ;;
                list-settings)
                        network_settings_list
@@ -1317,19 +1387,22 @@ cli_raw() {
                        zones_get_next_free
                        ;;
                list-zone-config-ids)
-                       zone_config_list_ids $@
+                       zone_config_list_ids "$@"
                        ;;
                list-zone-config-hids)
-                       zone_config_list_hids $@
+                       zone_config_list_hids "$@"
+                       ;;
+               vpn-security-policy-exists)
+                       vpn_security_policy_exists "$@"
                        ;;
                zone-name-is-valid)
-                       zone_name_is_valid $@
+                       zone_name_is_valid "$@"
                        ;;
                zone-config-id-is-valid)
-                       zone_config_id_is_valid $@
+                       zone_config_id_is_valid "$@"
                        ;;
                zone-config-hid-is-valid)
-                       zone_config_hid_is_valid $@
+                       zone_config_hid_is_valid "$@"
                        ;;
                *)
                        error "No such command: ${cmd}"
@@ -1343,29 +1416,36 @@ cli_raw() {
 # Process the given action
 case "${action}" in
        init)
-               init_run
+               # Update resolv.conf(5) when initializing the network
+               dns_generate_resolvconf
+
+               # Update bird configuration
+               bird_generate_config
+
+               # Also execute all triggers
+               triggers_execute_all "init"
                ;;
 
-       settings|hostname|port|device|zone|start|stop|restart|status|reset|route|vpn)
-               cli_${action} $@
+       settings|hostname|port|device|zone|start|stop|restart|status|reset|route|vpn|wireless)
+               cli_${action} "$@"
                ;;
 
        # DHCP server configuration (automatically detects which protocol to use).
        dhcpv6|dhcpv4)
-               cli_dhcpd ${action/dhcp/ip} $@
+               cli_dhcpd ${action/dhcp/ip} "$@"
                ;;
 
        # DNS server configuration.
        dns-server)
-               cli_dns_server $@
+               cli_dns_server "$@"
                ;;
 
        ""|help|--help|-h)
-               cli_help $@
+               cli_help "$@"
                ;;
 
        raw)
-               cli_raw $@
+               cli_raw "$@"
                ;;
 
        *)