forked from xapi-project/xen-api
-
Notifications
You must be signed in to change notification settings - Fork 0
/
netman.ml
73 lines (69 loc) · 2.28 KB
/
netman.ml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
(*
* Copyright (C) 2006-2009 Citrix Systems Inc.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published
* by the Free Software Foundation; version 2.1 only. with the special
* exception on linking described in file LICENSE.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*)
module D = Debug.Debugger(struct let name = "netman" end)
open D
type netty = Bridge of string | Vswitch of string | DriverDomain | Nat
let netty_of_bridge bridge =
match Netdev.network.Netdev.kind with
| Netdev.Bridge -> (Bridge bridge)
| Netdev.Vswitch -> (Vswitch bridge)
let online vif netty =
let setup_bridge_port dev =
Netdev.Link.down dev;
Netdev.Link.arp dev false;
Netdev.Link.multicast dev false;
Netdev.Link.set_addr dev
(if(Xc.is_fake ()) then "fe:fe:fe:fe:fe:fe" else "fe:ff:ff:ff:ff:ff");
Netdev.Addr.flush dev
in
match netty with
| Bridge bridgename ->
let add_to_bridge br dev =
Netdev.network.Netdev.set_forward_delay br 0;
Netdev.network.Netdev.intf_add br dev;
Netdev.Link.up dev
in
debug "Adding %s to bridge %s" vif bridgename;
setup_bridge_port vif;
add_to_bridge bridgename vif
| Vswitch bridgename ->
let add_to_bridge br dev =
Netdev.network.Netdev.intf_add br dev;
Netdev.Link.up dev
in
debug "Adding %s to bridge %s" vif bridgename;
setup_bridge_port vif;
add_to_bridge bridgename vif
| DriverDomain -> ()
| Nat -> failwith "not supported yet"
let offline vif netty =
match netty with
| Bridge bridgename ->
debug "Removing %s from bridge %s" vif bridgename;
begin try
Netdev.network.Netdev.intf_del bridgename vif;
Netdev.Link.down vif
with _ ->
warn "interface %s already removed from bridge %s" vif bridgename;
end;
| Vswitch bridgename ->
debug "Removing %s from bridge %s" vif bridgename;
begin try
Netdev.network.Netdev.intf_del bridgename vif;
Netdev.Link.down vif
with _ ->
warn "interface %s already removed from bridge %s" vif bridgename;
end;
| DriverDomain -> ()
| Nat -> failwith "not supported yet"