Skip to content

Commit

Permalink
CA-87787 - Listen on IPv6 if any IPv6 addresses configured
Browse files Browse the repository at this point in the history
Signed-off-by: Bob Ball <bob.ball@citrix.com>
  • Loading branch information
Bob Ball committed Aug 16, 2012
1 parent 28b2b95 commit 8d0adad
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 15 deletions.
2 changes: 1 addition & 1 deletion ocaml/xapi/xapi.ml
Expand Up @@ -307,7 +307,7 @@ let bring_up_management_if ~__context () =
if management_if = "" then begin
debug "No management interface defined (management is disabled)";
end else begin
Xapi_mgmt_iface.run management_if management_address_type;
Xapi_mgmt_iface.run ~__context management_if management_address_type;
match Helpers.get_management_ip_addr ~__context with
| Some "127.0.0.1" ->
debug "Received 127.0.0.1 as a management IP address; ignoring"
Expand Down
4 changes: 2 additions & 2 deletions ocaml/xapi/xapi_host.ml
Expand Up @@ -735,7 +735,7 @@ let get_management_interface ~__context ~host =

let change_management_interface ~__context interface primary_address_type =
debug "Changing management interface";
Xapi_mgmt_iface.run interface primary_address_type;
Xapi_mgmt_iface.run ~__context interface primary_address_type;
(* once the inventory file has been rewritten to specify new interface, sync up db with
state of world.. *)
Xapi_mgmt_iface.on_dom0_networking_change ~__context
Expand Down Expand Up @@ -795,7 +795,7 @@ let management_disable ~__context =
then raise (Api_errors.Server_error (Api_errors.slave_requires_management_iface, []));

Xapi_mgmt_iface.shutdown ();
Xapi_mgmt_iface.maybe_start_himn ();
Xapi_mgmt_iface.maybe_start_himn ~__context ();

(* Make sure all my PIFs are marked appropriately *)
Xapi_pif.update_management_flags ~__context ~host:(Helpers.get_localhost ~__context)
Expand Down
22 changes: 16 additions & 6 deletions ocaml/xapi/xapi_mgmt_iface.ml
Expand Up @@ -11,6 +11,7 @@
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*)
open Db_filter_types
open Pervasiveext
open Threadext

Expand Down Expand Up @@ -46,10 +47,19 @@ let stop () =
(* Even though xapi listens on all IP addresses, there is still an interface appointed as
* _the_ management interface. Slaves in a pool use the IP address of this interface to connect
* the pool master. *)
let start ?addr ~primary_address_type () =
let start ~__context ?addr () =
debug "Starting new server";
let localhost = Helpers.get_localhost ~__context in
let ipv6_pifs = Db.PIF.get_records_where ~__context
~expr:(
And (
Not (Eq (Field "ipv6_configuration_mode", Literal "None")),
Eq (Field "host", Literal (Ref.string_of localhost))
)
) in
let pif_address_type = if ipv6_pifs = [] then `IPv4 else `IPv6 in
let addr =
match addr, primary_address_type with
match addr, pif_address_type with
| None, `IPv4 -> Unix.inet_addr_any
| None, `IPv6 -> Unix.inet6_addr_any
| Some ip, _ ->
Expand Down Expand Up @@ -79,13 +89,13 @@ let change interface primary_address_type =
(Record_util.primary_address_type_to_string primary_address_type);
update_mh_info interface

let run interface primary_address_type =
let run ~__context interface primary_address_type =
Mutex.execute management_m (fun () ->
change interface primary_address_type;
if !himn_only then
stop ();
if !management_interface_server = None then
start ~primary_address_type ()
start ~__context ()
)

let shutdown () =
Expand All @@ -96,11 +106,11 @@ let shutdown () =
restart_stunnel ();
)

let maybe_start_himn ?addr () =
let maybe_start_himn ~__context ?addr () =
Mutex.execute management_m (fun () ->
Opt.iter (fun addr -> himn_addr := Some addr) addr;
if !management_interface_server = None then
Opt.iter (fun addr -> start ~addr ~primary_address_type:`IPv4 ()) !himn_addr
Opt.iter (fun addr -> start ~__context ~addr ()) !himn_addr
)

let management_ip_mutex = Mutex.create ()
Expand Down
4 changes: 2 additions & 2 deletions ocaml/xapi/xapi_mgmt_iface.mli
Expand Up @@ -27,11 +27,11 @@ val on_dom0_networking_change : __context:Context.t -> unit

(** Ensure the server thread listening on the management interface, and
* update the inventory file with the given interface (used for management traffic). *)
val run : string -> [< `IPv4 | `IPv6 ] -> unit
val run : __context:Context.t -> string -> [< `IPv4 | `IPv6 ] -> unit

(** Stop the server thread listening on the management interface *)
val shutdown : unit -> unit

(** Start a server thread on the given HIMN address if the server is not yet running *)
val maybe_start_himn : ?addr:string -> unit -> unit
val maybe_start_himn : __context:Context.t -> ?addr:string -> unit -> unit

8 changes: 4 additions & 4 deletions ocaml/xapi/xapi_network.ml
Expand Up @@ -27,14 +27,14 @@ let create_internal_bridge ~bridge ~uuid =
if not(List.mem bridge current) then Netdev.network.Netdev.add bridge ?uuid:(Some uuid);
if not(Netdev.Link.is_up bridge) then Netdev.Link.up bridge

let set_himn_ip bridge other_config =
let set_himn_ip ~__context bridge other_config =
if not(List.mem_assoc "ip_begin" other_config) then
error "Cannot setup host internal management network: no other-config:ip_begin"
else begin
(* Set the ip address of the bridge *)
let ip = List.assoc "ip_begin" other_config in
ignore(Forkhelpers.execute_command_get_output "/sbin/ifconfig" [bridge; ip; "up"]);
Xapi_mgmt_iface.maybe_start_himn ~addr:ip ()
Xapi_mgmt_iface.maybe_start_himn ~__context ~addr:ip ()
end

let check_himn ~__context =
Expand All @@ -52,7 +52,7 @@ let check_himn ~__context =
let dbg = Context.string_of_task __context in
let bridges = Net.Bridge.get_all dbg () in
if List.mem rc.API.network_bridge bridges then
set_himn_ip rc.API.network_bridge rc.API.network_other_config
set_himn_ip ~__context rc.API.network_bridge rc.API.network_other_config

let attach_internal ?(management_interface=false) ~__context ~self () =
let host = Helpers.get_localhost ~__context in
Expand All @@ -66,7 +66,7 @@ let attach_internal ?(management_interface=false) ~__context ~self () =
(* Check if we're a Host-Internal Management Network (HIMN) (a.k.a. guest-installer network) *)
if (List.mem_assoc Xapi_globs.is_guest_installer_network net.API.network_other_config)
&& (List.assoc Xapi_globs.is_guest_installer_network net.API.network_other_config = "true") then
set_himn_ip net.API.network_bridge net.API.network_other_config;
set_himn_ip ~__context net.API.network_bridge net.API.network_other_config;

(* Create the new PIF.
NB if we're doing this as part of a management-interface-reconfigure then
Expand Down

0 comments on commit 8d0adad

Please sign in to comment.