proto-shell: pass the interface name to plugins
authorFelix Fietkau <nbd@openwrt.org>
Sun, 11 Sep 2011 14:37:48 +0000 (16:37 +0200)
committerFelix Fietkau <nbd@openwrt.org>
Sun, 11 Sep 2011 14:37:48 +0000 (16:37 +0200)
proto-shell.c
proto/netifd-proto.sh
proto/ppp.sh

index ef6233f..8310f59 100644 (file)
@@ -59,7 +59,7 @@ proto_shell_handler(struct interface_proto_state *proto,
        struct proto_shell_handler *handler;
        const char *argv[6];
        char *config;
        struct proto_shell_handler *handler;
        const char *argv[6];
        char *config;
-       int ret;
+       int ret, i = 0;
 
        state = container_of(proto, struct proto_shell_state, proto);
        handler = state->handler;
 
        state = container_of(proto, struct proto_shell_state, proto);
        handler = state->handler;
@@ -68,25 +68,16 @@ proto_shell_handler(struct interface_proto_state *proto,
        if (!config)
                return -1;
 
        if (!config)
                return -1;
 
-       argv[0] = handler->script_name;
-       argv[1] = handler->proto.name;
-       argv[2] = "setup";
-       argv[3] = config;
-       argv[4] = NULL;
-       if (proto->iface->main_dev.dev) {
-               argv[4] = proto->iface->main_dev.dev->ifname;
-               argv[5] = NULL;
-       }
-
-       switch(cmd) {
-       case PROTO_CMD_TEARDOWN:
-               argv[2] = "teardown";
-               /* fall through */
-       case PROTO_CMD_SETUP:
-               ret = run_script(argv);
-               break;
-       }
+       argv[i++] = handler->script_name;
+       argv[i++] = handler->proto.name;
+       argv[i++] = cmd == PROTO_CMD_SETUP ? "setup" : "teardown";
+       argv[i++] = proto->iface->name;
+       argv[i++] = config;
+       if (proto->iface->main_dev.dev)
+               argv[i++] = proto->iface->main_dev.dev->ifname;
+       argv[i] = NULL;
 
 
+       ret = run_script(argv);
        free(config);
 
        return ret;
        free(config);
 
        return ret;
index 93bf37a..d15505c 100755 (executable)
@@ -26,10 +26,11 @@ add_default_handler() {
        esac
 }
 
        esac
 }
 
-proto="$1"
-cmd="$2"
-data="$3"
-ifname="$4"
+proto="$1"; shift
+cmd="$1"; shift
+interface="$1"; shift
+data="$1"; shift
+ifname="$1"; shift
 
 case "$cmd" in
        dump)
 
 case "$cmd" in
        dump)
@@ -55,8 +56,8 @@ case "$cmd" in
                        [[ "$proto" == "$1" ]] || return 0
 
                        case "$cmd" in
                        [[ "$proto" == "$1" ]] || return 0
 
                        case "$cmd" in
-                               setup) eval "$1_setup \"\$data\" \"\$ifname\"" ;;
-                               teardown) eval "$1_teardown \"\$data\" \"\$ifname\"" ;;
+                               setup) eval "$1_setup \"\$interface\" \"\$data\" \"\$ifname\"" ;;
+                               teardown) eval "$1_teardown \"\$interface\" \"\$data\" \"\$ifname\"" ;;
                                *) return 1 ;;
                        esac
                }
                                *) return 1 ;;
                        esac
                }
index 428096b..8e8ceb2 100755 (executable)
@@ -9,7 +9,7 @@ ppp_init_config() {
 }
 
 ppp_setup() {
 }
 
 ppp_setup() {
-       echo "ppp_setup: $1"
+       echo "ppp_setup($1): $2"
 }
 
 ppp_teardown() {
 }
 
 ppp_teardown() {
@@ -32,7 +32,7 @@ pppoe_init() {
 }
 
 pppoe_setup() {
 }
 
 pppoe_setup() {
-       echo "pppoe_setup($2): $1"
+       echo "pppoe_setup($1, $3): $2"
 }
 
 pppoe_teardown() {
 }
 
 pppoe_teardown() {