Skip to content

Commit bd4897b

Browse files
authored
Merge pull request #158 from psafont/upd-481
Backport CP-22034 to lcm branch
2 parents c0b8af3 + 8739904 commit bd4897b

File tree

7 files changed

+4740
-3732
lines changed

7 files changed

+4740
-3732
lines changed

_oasis

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,6 @@ Library networklibs
2828
xcp-inventory,
2929
xcp.network,
3030
systemd
31-
CSources: link_stubs.c, netdev.h
32-
CCOpt: -Wno-unused-function -g -ggdb
3331

3432
Executable xcp_networkd
3533
CompiledObject: best

_tags

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# OASIS_START
2-
# DO NOT EDIT (digest: 6789724751e66864fb1299d08f339eb0)
2+
# DO NOT EDIT (digest: d8db50fca5387e7a03bd4ad989bde930)
33
# Ignore VCS directories, you can use the same kind of rule outside
44
# OASIS_START/STOP if you want to exclude directories that contains
55
# useless stuff for the build process
@@ -18,23 +18,13 @@ true: annot, bin_annot
1818
"profiling/profiling.cmxs": use_profiling
1919
# Library networklibs
2020
"lib/networklibs.cmxs": use_networklibs
21-
<lib/*.ml{,i,y}>: oasis_library_networklibs_ccopt
22-
"lib/link_stubs.c": oasis_library_networklibs_ccopt
23-
<lib/networklibs.{cma,cmxa}>: use_libnetworklibs_stubs
2421
<lib/*.ml{,i,y}>: pkg_forkexec
2522
<lib/*.ml{,i,y}>: pkg_rpclib
2623
<lib/*.ml{,i,y}>: pkg_stdext
2724
<lib/*.ml{,i,y}>: pkg_systemd
2825
<lib/*.ml{,i,y}>: pkg_threads
2926
<lib/*.ml{,i,y}>: pkg_xcp-inventory
3027
<lib/*.ml{,i,y}>: pkg_xcp.network
31-
"lib/link_stubs.c": pkg_forkexec
32-
"lib/link_stubs.c": pkg_rpclib
33-
"lib/link_stubs.c": pkg_stdext
34-
"lib/link_stubs.c": pkg_systemd
35-
"lib/link_stubs.c": pkg_threads
36-
"lib/link_stubs.c": pkg_xcp-inventory
37-
"lib/link_stubs.c": pkg_xcp.network
3828
# Executable xcp_networkd
3929
<networkd/networkd.{native,byte}>: pkg_forkexec
4030
<networkd/networkd.{native,byte}>: pkg_netlink
@@ -139,4 +129,3 @@ true: annot, bin_annot
139129
<test/*.ml{,i,y}>: pkg_xcp.network
140130
<test/*.ml{,i,y}>: use_networklibs
141131
# OASIS_STOP
142-

lib/link_stubs.c

Lines changed: 0 additions & 179 deletions
This file was deleted.

lib/network_utils.ml

Lines changed: 12 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,18 @@ module Sysfs = struct
179179
let get_all_bridges () =
180180
let ifaces = list () in
181181
List.filter (fun name -> Sys.file_exists (getpath name "bridge")) ifaces
182+
183+
(** Returns (speed, duplex) for a given network interface: int megabits/s, Duplex.
184+
* The units of speed are specified in pif_record in xen-api/xapi/records.ml.
185+
* Note: these data are present in sysfs from kernel 2.6.33. *)
186+
let get_status name =
187+
let speed = getpath name "speed"
188+
|> (fun p -> try (read_one_line p |> int_of_string) with _ -> 0)
189+
in
190+
let duplex = getpath name "duplex"
191+
|> (fun p -> try read_one_line p |> duplex_of_string with _ -> Duplex_unknown)
192+
in (speed, duplex)
193+
182194
end
183195

184196
module Ip = struct
@@ -1090,37 +1102,3 @@ module Ethtool = struct
10901102
if options <> [] then
10911103
ignore (call ~log:true ("-K" :: name :: (List.concat (List.map (fun (k, v) -> [k; v]) options))))
10921104
end
1093-
1094-
module Bindings = struct
1095-
let control_socket () =
1096-
try
1097-
Unix.socket Unix.PF_INET Unix.SOCK_DGRAM 0
1098-
with
1099-
exn ->
1100-
try
1101-
Unix.socket Unix.PF_UNIX Unix.SOCK_DGRAM 0
1102-
with
1103-
exn ->
1104-
Unix.socket Unix.PF_INET6 Unix.SOCK_DGRAM 0
1105-
1106-
let with_fd f =
1107-
let fd = control_socket () in
1108-
let r = begin try
1109-
f fd
1110-
with
1111-
exn ->
1112-
Unix.close fd;
1113-
raise exn
1114-
end in
1115-
Unix.close fd;
1116-
r
1117-
1118-
external _get_status : Unix.file_descr -> string -> int * duplex = "stub_link_get_status"
1119-
1120-
(** Returns speed and duplex for a given network interface.
1121-
* Note: from kernel 2.6.33, this information is also present in sysfs. *)
1122-
let get_status name =
1123-
try
1124-
with_fd (fun fd -> _get_status fd name)
1125-
with _ -> raise (Read_error "stub_link_get_status")
1126-
end

0 commit comments

Comments
 (0)