]> git.ipfire.org Git - people/ms/network.git/blobdiff - src/network
dns: Better propagate known DNS servers
[people/ms/network.git] / src / network
index 3d3b31ab80fb23063d8087873e2149421cfbcb02..4d23e5041b51e0707deefae72b1280f9cdd274ef 100644 (file)
@@ -38,7 +38,7 @@ done
 # Read network settings
 network_settings_read
 
-function cli_settings() {
+cli_settings() {
        if cli_help_requested $@; then
                cli_show_man network-settings
                exit ${EXIT_OK}
@@ -52,50 +52,60 @@ function cli_settings() {
        fi
 }
 
-function cli_device() {
+cli_device() {
        if cli_help_requested $@; then
                cli_show_man network-device
                exit ${EXIT_OK}
        fi
 
-       local device=${1}
-       local action=${2}
-       shift 2
-
-       if ! isset device; then
-               cli_show_man network-device
-               return ${EXIT_ERROR}
-       fi
-
-       assert device_exists ${device}
+       local action="${1}"
+       shift
 
        case "${action}" in
-               discover)
-                       cli_device_discover ${device} $@
-                       ;;
-               monitor)
-                       cli_device_monitor "${device}" $@
-                       ;;
-               status)
-                       cli_device_status ${device}
-                       ;;
-               unlock)
-                       cli_device_serial_unlock ${device} $@
-                       ;;
-               ussd)
-                       cli_device_send_ussd_command "${device}" $@
+               list)
+                       cli_device_list $@
                        ;;
                *)
-                       cli_show_man network-device
+                       local device="${action}"
+                       action="${1}"
+                       shift
+
+                       if ! isset device; then
+                               cli_show_man network-device
+                               return ${EXIT_ERROR}
+                       fi
+
+                       assert device_exists ${device}
+
+                       case "${action}" in
+                               discover)
+                                       cli_device_discover ${device} $@
+                                       ;;
+                               monitor)
+                                       cli_device_monitor "${device}" $@
+                                       ;;
+                               status)
+                                       cli_device_status ${device}
+                                       ;;
+                               unlock)
+                                       cli_device_serial_unlock ${device} $@
+                                       ;;
+                               ussd)
+                                       cli_device_send_ussd_command "${device}" $@
+                                       ;;
+                               *)
+                                       cli_show_man network-device
+                                       ;;
+                       esac
                        ;;
        esac
 
        return ${EXIT_OK}
 }
 
-function cli_device_status() {
-       local device=${1}
-       assert device_exists ${device}
+cli_device_status() {
+       local device="${1}"
+       assert isset device
 
        # Disable debugging output here.
        local log_disable_stdout=${LOG_DISABLE_STDOUT}
@@ -107,11 +117,17 @@ function cli_device_status() {
        cli_headline 1 "Device status: ${device}"
        cli_print_fmt1 1 "Name"         "${device}"
 
-       # Handle serial devices.
-       if [ "${type}" = "serial" ]; then
-               cli_device_status_serial ${device}
-               return $?
-       fi
+       # Handle special devices
+       case "${type}" in
+               phy)
+                       cli_device_status_phy "${device}"
+                       return $?
+                       ;;
+               serial)
+                       cli_device_status_serial "${device}"
+                       return $?
+                       ;;
+       esac
 
        # Print the device status.
        device_is_up ${device} &>/dev/null
@@ -170,11 +186,23 @@ function cli_device_status() {
                cli_space
        fi
 
+       case "${type}" in
+               wireless*)
+                       local phy="$(device_get_phy "${device}")"
+                       if isset phy; then
+                               cli_headline 2 "PHY"
+                               cli_print_fmt1 2 "Name" "${phy}"
+                               cli_print_fmt1 2 "Address" "$(phy_get_address "${phy}")"
+                               cli_space
+                       fi
+                       ;;
+       esac
+
        # Reset the logging level.
        LOG_DISABLE_STDOUT=${log_disable_stdout}
 }
 
-function cli_device_status_serial() {
+cli_device_status_serial() {
        local device=${1}
        assert device_is_serial ${device}
 
@@ -235,7 +263,29 @@ function cli_device_status_serial() {
        cli_space
 }
 
-function cli_device_discover() {
+cli_device_status_phy() {
+       local phy="${1}"
+       assert phy_exists "${phy}"
+
+       local address="$(phy_get_address "${phy}")"
+       cli_print_fmt1 1 "Address" "${address}"
+       cli_space
+
+       local devices="$(phy_get_devices "${phy}")"
+       if isset devices; then
+               cli_headline 2 "Soft interfaces"
+
+               local device
+               for device in ${devices}; do
+                       cli_print 2 "* %s" "${device}"
+               done
+               cli_space
+       fi
+
+       return ${EXIT_OK}
+}
+
+cli_device_discover() {
        local device=${1}
        shift
 
@@ -306,7 +356,7 @@ function cli_device_discover() {
        [ "${up}" = "1" ] || device_set_down ${device}
 }
 
-function cli_device_serial_unlock() {
+cli_device_serial_unlock() {
        if cli_help_requested $@; then
                cli_show_man network-device
                exit ${EXIT_OK}
@@ -392,7 +442,7 @@ function cli_device_serial_unlock() {
        exit $?
 }
 
-function cli_device_send_ussd_command() {
+cli_device_send_ussd_command() {
        local device="${1}"
        assert isset device
        shift
@@ -427,7 +477,7 @@ function cli_device_send_ussd_command() {
        exit $?
 }
 
-function cli_device_monitor() {
+cli_device_monitor() {
        local device="${1}"
        assert isset device
 
@@ -440,7 +490,16 @@ function cli_device_monitor() {
        exit $?
 }
 
-function cli_hostname() {
+cli_device_list() {
+       local device
+       for device in $(device_list); do
+               cli_device_status "${device}"
+       done
+
+       exit ${EXIT_OK}
+}
+
+cli_hostname() {
        if cli_help_requested $@; then
                cli_show_man network
                exit ${EXIT_OK}
@@ -459,7 +518,7 @@ function cli_hostname() {
        exit ${EXIT_OK}
 }
 
-function cli_port() {
+cli_port() {
        if cli_help_requested $@; then
                cli_show_man network-port
                exit ${EXIT_OK}
@@ -498,7 +557,7 @@ function cli_port() {
        fi
 }
 
-function cli_zone() {
+cli_zone() {
        if cli_help_requested $@; then
                cli_show_man network-zone
                exit ${EXIT_OK}
@@ -544,7 +603,7 @@ function cli_zone() {
 
                case "${action}" in
                        new)
-                               zone_new $@
+                               cli_zone_new $@
                                ;;
                        destroy)
                                cli_zone_destroy $@
@@ -565,10 +624,19 @@ function cli_zone() {
        fi
 }
 
+cli_zone_new() {
+       if cli_help_requested $@ || [ $# -lt 2 ]; then
+               cli_show_man network-zone-new
+               exit ${EXIT_OK}
+       fi
+
+       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.
-function cli_zone_destroy() {
+cli_zone_destroy() {
        if cli_help_requested $@; then
                cli_show_man network-zone
                exit ${EXIT_OK}
@@ -588,7 +656,7 @@ function cli_zone_destroy() {
        exit ${EXIT_OK}
 }
 
-function cli_zone_port() {
+cli_zone_port() {
        if cli_help_requested $@; then
                cli_show_man network-zone-port
                exit ${EXIT_OK}
@@ -632,7 +700,7 @@ function cli_zone_port() {
        exit ${EXIT_OK}
 }
 
-function cli_list_hooks() {
+cli_list_hooks() {
        local type=${1}
        shift
 
@@ -652,7 +720,7 @@ function cli_list_hooks() {
        done | sort -u
 }
 
-function cli_route() {
+cli_route() {
        if cli_help_requested $@; then
                cli_show_man network-route
                exit ${EXIT_OK}
@@ -689,7 +757,7 @@ function cli_route() {
        exit ${EXIT_OK}
 }
 
-function cli_dhcpd() {
+cli_dhcpd() {
        local proto=${1}
        shift
 
@@ -731,7 +799,7 @@ function cli_dhcpd() {
        exit ${EXIT_OK}
 }
 
-function cli_dhcpd_show() {
+cli_dhcpd_show() {
        local proto=${1}
        assert isset proto
 
@@ -801,7 +869,7 @@ function cli_dhcpd_show() {
        fi
 }
 
-function cli_dhcpd_subnet() {
+cli_dhcpd_subnet() {
        local proto=${1}
        shift
 
@@ -878,7 +946,7 @@ function cli_dhcpd_subnet() {
        exit ${EXIT_OK}
 }
 
-function cli_dhcpd_subnet_range() {
+cli_dhcpd_subnet_range() {
        local proto=${1}
        assert isset proto
        shift
@@ -907,7 +975,7 @@ function cli_dhcpd_subnet_range() {
        esac
 }
 
-function cli_dhcpd_subnet_show() {
+cli_dhcpd_subnet_show() {
        local proto=${1}
        assert isset proto
 
@@ -930,14 +998,14 @@ function cli_dhcpd_subnet_show() {
 
        # Read the options.
        local -A options
-       dhcpd_subnet_options_read ${proto} ${subnet_id}
+       dhcpd_subnet_options_read "${proto}" "${subnet_id}"
 
        # Print the options if any.
        if [ ${#options[*]} -gt 0 ]; then
                cli_headline $(( ${level} + 2 )) "Options"
 
                local option
-               for option in $(dhcpd_subnet_options ${proto}); do
+               for option in $(dhcpd_subnet_options_list ${proto}); do
                        [ -n "${options[${option}]}" ] || continue
 
                        cli_print_fmt1 $(( ${level} + 2 )) \
@@ -965,7 +1033,7 @@ function cli_dhcpd_subnet_show() {
        cli_space
 }
 
-function cli_dhcpd_options() {
+cli_dhcpd_subnet_options() {
        local proto=${1}
        assert isset proto
        shift
@@ -974,8 +1042,6 @@ function cli_dhcpd_options() {
        assert isset subnet_id
        shift
 
-       local valid_options=$(dhcpd_subnet_options ${proto})
-
        local key val
        while [ $# -gt 0 ]; do
                case "${1}" in
@@ -988,7 +1054,7 @@ function cli_dhcpd_options() {
        done
 }
 
-function cli_start() {
+cli_start() {
        if cli_help_requested $@; then
                cli_show_man network
                exit ${EXIT_OK}
@@ -1004,7 +1070,7 @@ function cli_start() {
        wait # until everything is settled
 }
 
-function cli_stop() {
+cli_stop() {
        if cli_help_requested $@; then
                cli_show_man network
                exit ${EXIT_OK}
@@ -1020,7 +1086,7 @@ function cli_stop() {
        wait # until everything is settled
 }
 
-function cli_restart() {
+cli_restart() {
        if cli_help_requested $@; then
                cli_show_man network
                exit ${EXIT_OK}
@@ -1034,7 +1100,7 @@ function cli_restart() {
        cli_start $@
 }
 
-function cli_status() {
+cli_status() {
        if cli_help_requested $@; then
                cli_show_man network
                exit ${EXIT_OK}
@@ -1057,7 +1123,7 @@ function cli_status() {
        LOG_DISABLE_STDOUT=${log_disable_stdout}
 }
 
-function cli_reset() {
+cli_reset() {
        if cli_help_requested $@; then
                cli_show_man network
                exit ${EXIT_OK}
@@ -1107,7 +1173,7 @@ function cli_reset() {
 # Help function: will show the default man page to the user.
 # Optionally, there are two arguments taken, the type of hook
 # and which hook should be shown.
-function cli_help() {
+cli_help() {
        local type=${1}
        local what=${2}
 
@@ -1130,7 +1196,7 @@ function cli_help() {
        hook_exec ${type} ${what} help
 }
 
-function cli_dns_server() {
+cli_dns_server() {
        if cli_help_requested $@; then
                cli_show_man network-dns-server
                exit ${EXIT_OK}
@@ -1149,7 +1215,7 @@ function cli_dns_server() {
 
        case "${cmd}" in
                list)
-                       dns_server_list
+                       dns_server_show
                        exit ${EXIT_OK}
                        ;;
                add)
@@ -1179,8 +1245,61 @@ function cli_dns_server() {
        esac
 
        # Update the local DNS configuration after changes have been made.
-       dns_generate_resolvconf
-       radvd_update
+       dns_server_update
+
+       exit ${EXIT_OK}
+}
+
+cli_raw() {
+       local cmd="${1}"
+       assert isset cmd
+       shift
+
+       case "${cmd}" in
+               db-dump)
+                       db_dump
+                       ;;
+               list-devices)
+                       device_list
+                       ;;
+               list-dhcpd-ranges-of-subnet)
+                       dhcpd_subnet_range_list $@
+                       ;;
+               list-dhcpd-settings)
+                       dhcpd_global_settings_list $@
+                       ;;
+               list-dhcpd-subnets)
+                       dhcpd_subnet_list $@
+                       ;;
+               list-dhcpd-subnet-options)
+                       dhcpd_subnet_options_list $@
+                       ;;
+               list-dns-servers)
+                       dns_server_list
+                       ;;
+               list-free-ports)
+                       port_list_free
+                       ;;
+               list-hooks)
+                       hook_list $@
+                       ;;
+               list-ports)
+                       port_list
+                       ;;
+               list-ports-of-zone)
+                       zone_get_ports $@
+                       ;;
+               list-settings)
+                       network_settings_list
+                       ;;
+               list-zones)
+                       zones_get_all
+                       ;;
+               *)
+                       error "No such command: ${cmd}"
+                       exit ${EXIT_ERROR}
+                       ;;
+       esac
 
        exit ${EXIT_OK}
 }
@@ -1209,6 +1328,10 @@ case "${action}" in
                cli_help $@
                ;;
 
+       raw)
+               cli_raw $@
+               ;;
+
        *)
                error "Invalid command given: ${action}"
                cli_usage "network help"