]> xenbits.xen.org Git - xenclient/toolstack.git/commitdiff
Revert "[xenvm] Move the network manager tracking code to xenmgr where it belongs...
authorJean Guyader <jean.guyader@eu.citrix.com>
Sat, 23 Jan 2010 16:39:53 +0000 (16:39 +0000)
committerJean Guyader <jean.guyader@eu.citrix.com>
Sat, 23 Jan 2010 16:39:53 +0000 (16:39 +0000)
This reverts commit dd290f39d68fcd84c6158d1386d58e52b9139549.

xenvm/network_manager.ml [new file with mode: 0644]
xenvm/xenvm.ml

diff --git a/xenvm/network_manager.ml b/xenvm/network_manager.ml
new file mode 100644 (file)
index 0000000..8d717fc
--- /dev/null
@@ -0,0 +1,99 @@
+open Vmstate
+
+module D=Debug.Debugger(struct let name="xenvm" end)
+open D
+
+type devstate =
+       NM_DEVICE_STATE_UNKNOWN
+      | NM_DEVICE_STATE_UNMANAGED
+      | NM_DEVICE_STATE_UNAVAILABLE
+      | NM_DEVICE_STATE_DISCONNECTED
+      | NM_DEVICE_STATE_PREPARE
+      | NM_DEVICE_STATE_CONFIG
+      | NM_DEVICE_STATE_NEED_AUTH
+      | NM_DEVICE_STATE_IP_CONFIG
+      | NM_DEVICE_STATE_ACTIVATED
+      | NM_DEVICE_STATE_FAILED
+
+let devstate_of_int = function
+      | 1 -> NM_DEVICE_STATE_UNMANAGED
+      | 2 -> NM_DEVICE_STATE_UNAVAILABLE
+      | 3 -> NM_DEVICE_STATE_DISCONNECTED
+      | 4 -> NM_DEVICE_STATE_PREPARE
+      | 5 -> NM_DEVICE_STATE_CONFIG
+      | 6 -> NM_DEVICE_STATE_NEED_AUTH
+      | 7 -> NM_DEVICE_STATE_IP_CONFIG
+      | 8 -> NM_DEVICE_STATE_ACTIVATED
+      | 9 -> NM_DEVICE_STATE_FAILED
+      | _ -> NM_DEVICE_STATE_UNKNOWN
+
+let get_devstate bus path =
+       let call = DBus.Message.new_method_call 
+                       "org.freedesktop.NetworkManager" path "org.freedesktop.DBus.Properties" "Get" in
+       DBus.Message.append call [DBus.String "org.freedesktop.NetworkManager.Device";
+                                 DBus.String "State"];
+       let resp = DBus.Connection.send_with_reply_and_block bus call (-1) in
+       match DBus.Message.get_type resp with
+       | DBus.Message.Method_return ->
+                 (match DBus.Message.get resp with
+                 | [DBus.Variant (DBus.UInt32 state)] ->
+                           devstate_of_int (Int32.to_int state)
+                 | _ -> failwith "Unexpected response")
+       | _ -> failwith "Failed to get device state"
+
+let get_devintf bus path =
+       let call = DBus.Message.new_method_call 
+                       "org.freedesktop.NetworkManager" path "org.freedesktop.DBus.Properties" "Get" in
+       DBus.Message.append call [DBus.String "org.freedesktop.NetworkManager.Device";
+                                 DBus.String "Interface"];
+       let resp = DBus.Connection.send_with_reply_and_block bus call (-1) in
+       match DBus.Message.get_type resp with
+       | DBus.Message.Method_return ->
+                 (match DBus.Message.get resp with
+                 | [DBus.Variant (DBus.String intf)] ->
+                           intf
+                 | _ -> failwith "Unexpected response")
+       | _ -> failwith "Failed to get interface name"
+
+let when_conn_changed xs state nic_id news olds =
+       if news <> olds then (
+               let xsnode = Printf.sprintf "/local/domain/%d/device/vif/%d/disconnect" state.vm_domid nic_id in
+               match news, olds with
+               | NM_DEVICE_STATE_ACTIVATED, _ ->
+                         info "Detected active net connection (NetworkManager) for id %d" nic_id;
+                         xs.Xs.write xsnode "0";
+               | _, NM_DEVICE_STATE_ACTIVATED ->
+                         info "Detected inactive net connection (NetworkManager) for id %d" nic_id;
+                         xs.Xs.write xsnode "1";
+               | _ -> ()
+        )
+       
+let process_signal state xs bus msg =
+       let interface = match DBus.Message.get_interface msg with None -> "" | Some i -> i in
+       let member    = match DBus.Message.get_member msg    with None -> "" | Some m -> m in
+       let path      = match DBus.Message.get_path msg      with None -> "" | Some p -> p in
+       let params    = DBus.Message.get msg in
+       match interface, member, params with
+       | "org.freedesktop.NetworkManager.Device",
+         "StateChanged",
+         [DBus.UInt32 news; DBus.UInt32 olds; DBus.UInt32 reason] ->
+                 (* new state *)
+                 let news = devstate_of_int (Int32.to_int news) in
+                 (* previous state *)
+                 let olds = devstate_of_int (Int32.to_int olds) in
+                 let nics =
+                         let intf = get_devintf bus path in
+                         match intf with
+                         | "brbridged" ->
+                                   (* it is wired connection which has changed state *)
+                                   List.find_all (fun n ->
+                                           n.ns_bridge = "brshared"  ||
+                                           n.ns_bridge = "brbridged" ||
+                                           n.ns_bridge = "brinternal") state.vm_nics
+                         | _ ->
+                                   (* it is wireless connection which has changed state *)
+                                   List.find_all (fun n -> n.ns_bridge = "brwireless") state.vm_nics
+                 in
+                 List.iter (fun nic -> when_conn_changed xs state nic.ns_id news olds) nics
+       | _ -> ()
+                         
index 1639c845480c614d7ec4aff10832a5db706254aa..cc26a97e3e3d50937f08dda8f95c28504c9e67e5 100644 (file)
@@ -818,7 +818,8 @@ let monitor_rpc_dbus state =
                        Some (err_msg)
                in
        let process_signal msg =
-               ()
+               (* handle network manager signals *)
+               with_xs (fun xs -> Network_manager.process_signal state xs bus msg)
        in
        let process_message msg =
                let ty = DBus.Message.get_type msg in