]> git.ipfire.org Git - people/ms/mstpd.git/commitdiff
Notify mstpd about stp mode change via bridge-stp
authordv1tas <dv1tas@fbe50366-0c72-4402-a84b-5d246361dba7>
Thu, 24 Nov 2011 19:02:20 +0000 (19:02 +0000)
committerdv1tas <dv1tas@fbe50366-0c72-4402-a84b-5d246361dba7>
Thu, 24 Nov 2011 19:02:20 +0000 (19:02 +0000)
git-svn-id: svn://svn.code.sf.net/p/mstpd/code/trunk@19 fbe50366-0c72-4402-a84b-5d246361dba7

bridge-stp
bridge_track.c
ctl_functions.h
ctl_main.c
ctl_socket_server.c

index 6bed90d849bb01f15bd24256c8f878766e3b040d..77e2d2e755c4c63b28190cbb0d3f323d9f2d56b4 100755 (executable)
@@ -44,12 +44,13 @@ case $2 in
         checkpid $pid_file || exit 1
         for b in $MSTP_BRIDGES; do
             if [ "$bridge" == "$b" ]; then
-                exit 0;
+                exec /sbin/mstpctl notify-daemon-that-stp-is-on $bridge
             fi
         done
         exit 1 ;;
     stop)
-        exit 0 ;;
+        exec /sbin/mstpctl notify-daemon-that-stp-is-off $bridge
+        ;;
     *)
         echo "Unknown action:" $2
         echo "Usage: bridge-stp <bridge> {start|stop}"
index e559ba2f44fe97582d69808ea34b1132eb43d2a6..75cce58da1eb616a84281d86385c3320902dc065 100644 (file)
@@ -175,7 +175,7 @@ static bool check_mac_address(char *name, __u8 *addr)
     }
 }
 
-static int stp_enabled(bridge_t * br)
+static bool stp_enabled(bridge_t * br)
 {
     char path[40 + IFNAMSIZ];
     sprintf(path, "/sys/class/net/%s/bridge/stp_state", br->sysdeps.name);
@@ -189,9 +189,8 @@ static int stp_enabled(bridge_t * br)
     return enabled == 2; /* ie user mode STP */
 }
 
-static void set_br_up(bridge_t * br, bool up)
+static void set_br_up(bridge_t * br, bool up, bool stp_up)
 {
-    int stp_up = stp_enabled(br);
     INFO("%s was %s stp was %s", br->sysdeps.name,
          br->sysdeps.up ? "up" : "down", br->sysdeps.stp_up ? "up" : "down");
     INFO("Set bridge %s %s stp %s" , br->sysdeps.name,
@@ -300,7 +299,7 @@ int bridge_notify(int br_index, int if_index, bool newlink, unsigned flags)
         }
         int br_flags = get_flags(br->sysdeps.name);
         if(br_flags >= 0)
-            set_br_up(br, !!(br_flags & IFF_UP));
+            set_br_up(br, !!(br_flags & IFF_UP), stp_enabled(br));
     }
 
     if(br)
@@ -367,7 +366,7 @@ int bridge_notify(int br_index, int if_index, bool newlink, unsigned flags)
                         return -1;
                     }
                 }
-                set_br_up(br, up);
+                set_br_up(br, up, stp_enabled(br));
             }
         }
     }
@@ -840,3 +839,13 @@ int CTL_set_fids2mstids(int br_index, __u16 *fids2mstids)
     CTL_CHECK_BRIDGE;
     return MSTP_IN_set_all_fids2mstids(br, fids2mstids) ? 0 : -1;
 }
+
+int CTL_stp_mode_notification(int br_index, bool on)
+{
+    int br_flags;
+    CTL_CHECK_BRIDGE;
+    if(0 > (br_flags = get_flags(br->sysdeps.name)))
+        return br_flags;
+    set_br_up(br, !!(br_flags & IFF_UP), on);
+    return 0;
+}
index da22daef39ddfff712d3cfdfd99175161d973419..1af60004a0d68157fcbb1aaf3536124324b4fc00 100644 (file)
@@ -57,6 +57,9 @@ typedef struct _log_string
 
 #define MSTP_SERVER_SOCK_NAME ".mstp_server"
 
+/* Commands sent from bridge-stp script needs this flag */
+#define RESPONSE_FIRST_HANDLE_LATER     0x10000
+
 /* COMMANDS */
 #define CTL_DECLARE(name) \
 int CTL_ ## name name ## _ARGS
@@ -445,6 +448,23 @@ struct set_fids2mstids_OUT
 #define set_fids2mstids_CALL (in->br_index, in->fids2mstids)
 CTL_DECLARE(set_fids2mstids);
 
+/* stp_mode_notification */
+#define CMD_CODE_stp_mode_notification  (122 | RESPONSE_FIRST_HANDLE_LATER)
+#define stp_mode_notification_ARGS (int br_index, bool on)
+struct stp_mode_notification_IN
+{
+    int br_index;
+    bool on;
+};
+struct stp_mode_notification_OUT
+{
+};
+#define stp_mode_notification_COPY_IN  ({ in->br_index = br_index; \
+                                          in->on = on; })
+#define stp_mode_notification_COPY_OUT ({ (void)0; })
+#define stp_mode_notification_CALL (in->br_index, in->on)
+CTL_DECLARE(stp_mode_notification);
+
 /* General case part in ctl command server switch */
 #define SERVER_MESSAGE_CASE(name)                            \
     case CMD_CODE_ ## name : do                              \
index 5473a1826f95bcb3a5d99b0a1f1d13fa938842f0..c294b9cf963a473d843d04f8872b54205d43a849 100644 (file)
@@ -908,6 +908,14 @@ static int cmd_setfid2mstid(int argc, char *const *argv)
     return CTL_set_fid2mstid(br_index, fid, mstid);
 }
 
+static int cmd_stp_mode_notification(int argc, char *const *argv, bool on)
+{
+    int br_index = get_index(argv[1], "bridge");
+    if(0 > br_index)
+        return br_index;
+    return CTL_stp_mode_notification(br_index, on);
+}
+
 struct command
 {
     int nargs;
@@ -1070,6 +1078,12 @@ int main(int argc, char *const *argv)
     argv += optind;
     if(NULL == (cmd = command_lookup(argv[0])))
     {
+        /* Two special commands not intended for interactive use */
+        if(!strcmp(argv[0], "notify-daemon-that-stp-is-on"))
+            return cmd_stp_mode_notification(argc, argv, true);
+        if(!strcmp(argv[0], "notify-daemon-that-stp-is-off"))
+            return cmd_stp_mode_notification(argc, argv, false);
+
         fprintf(stderr, "never heard of command [%s]\n", argv[0]);
         goto help;
     }
@@ -1111,6 +1125,7 @@ CLIENT_SIDE_FUNCTION(set_vid2fid)
 CLIENT_SIDE_FUNCTION(set_fid2mstid)
 CLIENT_SIDE_FUNCTION(set_vids2fids)
 CLIENT_SIDE_FUNCTION(set_fids2mstids)
+CLIENT_SIDE_FUNCTION(stp_mode_notification)
 
 /*********************** Logging *********************/
 
index 27f01a632747b03e0cd64178cacabf70cf24722e..4650c9ca5840d94276332ab016240d91b61494cf 100644 (file)
@@ -82,6 +82,7 @@ static int handle_message(int cmd, void *inbuf, int lin,
         SERVER_MESSAGE_CASE(set_fid2mstid);
         SERVER_MESSAGE_CASE(set_vids2fids);
         SERVER_MESSAGE_CASE(set_fids2mstids);
+        SERVER_MESSAGE_CASE(stp_mode_notification);
 
         default:
             ERROR("CTL: Unknown command %d", cmd);
@@ -150,8 +151,11 @@ static void ctl_rcv_handler(uint32_t events, struct epoll_event_handler *p)
     msg_log_offset = 0;
     ctl_in_handler = 1;
 
-    mhdr.res = handle_message(mhdr.cmd, msg_inbuf, mhdr.lin,
-                              msg_outbuf, mhdr.lout);
+    if(!(mhdr.cmd & RESPONSE_FIRST_HANDLE_LATER))
+        mhdr.res = handle_message(mhdr.cmd, msg_inbuf, mhdr.lin,
+                                  msg_outbuf, mhdr.lout);
+    else
+        mhdr.res = 0;
 
     ctl_in_handler = 0;
     if(0 > mhdr.res)
@@ -172,6 +176,9 @@ static void ctl_rcv_handler(uint32_t events, struct epoll_event_handler *p)
             ("CTL: Couldn't send full response, sent %d bytes instead of %zd.",
              l, sizeof(mhdr) + mhdr.lout + mhdr.llog);
     }
+
+    if(mhdr.cmd & RESPONSE_FIRST_HANDLE_LATER)
+        handle_message(mhdr.cmd, msg_inbuf, mhdr.lin, msg_outbuf, mhdr.lout);
 }
 
 static struct epoll_event_handler ctl_handler = {0};