cgroup-network.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712
  1. // SPDX-License-Identifier: GPL-3.0-or-later
  2. #include "libnetdata/libnetdata.h"
  3. #ifdef HAVE_SETNS
  4. #ifndef _GNU_SOURCE
  5. #define _GNU_SOURCE /* See feature_test_macros(7) */
  6. #endif
  7. #include <sched.h>
  8. #endif
  9. char environment_variable2[FILENAME_MAX + 50] = "";
  10. char *environment[] = {
  11. "PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin",
  12. environment_variable2,
  13. NULL
  14. };
  15. // ----------------------------------------------------------------------------
  16. // callback required by fatal()
  17. void netdata_cleanup_and_exit(int ret) {
  18. exit(ret);
  19. }
  20. void send_statistics( const char *action, const char *action_result, const char *action_data) {
  21. (void) action;
  22. (void) action_result;
  23. (void) action_data;
  24. return;
  25. }
  26. // callbacks required by popen()
  27. void signals_block(void) {};
  28. void signals_unblock(void) {};
  29. void signals_reset(void) {};
  30. // callback required by eval()
  31. int health_variable_lookup(const char *variable, uint32_t hash, struct rrdcalc *rc, calculated_number *result) {
  32. (void)variable;
  33. (void)hash;
  34. (void)rc;
  35. (void)result;
  36. return 0;
  37. };
  38. // required by get_system_cpus()
  39. char *netdata_configured_host_prefix = "";
  40. // ----------------------------------------------------------------------------
  41. struct iface {
  42. const char *device;
  43. uint32_t hash;
  44. unsigned int ifindex;
  45. unsigned int iflink;
  46. struct iface *next;
  47. };
  48. unsigned int read_iface_iflink(const char *prefix, const char *iface) {
  49. if(!prefix) prefix = "";
  50. char filename[FILENAME_MAX + 1];
  51. snprintfz(filename, FILENAME_MAX, "%s/sys/class/net/%s/iflink", prefix, iface);
  52. unsigned long long iflink = 0;
  53. int ret = read_single_number_file(filename, &iflink);
  54. if(ret) error("Cannot read '%s'.", filename);
  55. return (unsigned int)iflink;
  56. }
  57. unsigned int read_iface_ifindex(const char *prefix, const char *iface) {
  58. if(!prefix) prefix = "";
  59. char filename[FILENAME_MAX + 1];
  60. snprintfz(filename, FILENAME_MAX, "%s/sys/class/net/%s/ifindex", prefix, iface);
  61. unsigned long long ifindex = 0;
  62. int ret = read_single_number_file(filename, &ifindex);
  63. if(ret) error("Cannot read '%s'.", filename);
  64. return (unsigned int)ifindex;
  65. }
  66. struct iface *read_proc_net_dev(const char *scope __maybe_unused, const char *prefix) {
  67. if(!prefix) prefix = "";
  68. procfile *ff = NULL;
  69. char filename[FILENAME_MAX + 1];
  70. snprintfz(filename, FILENAME_MAX, "%s%s", prefix, (*prefix)?"/proc/1/net/dev":"/proc/net/dev");
  71. #ifdef NETDATA_INTERNAL_CHECKS
  72. info("parsing '%s'", filename);
  73. #endif
  74. ff = procfile_open(filename, " \t,:|", PROCFILE_FLAG_DEFAULT);
  75. if(unlikely(!ff)) {
  76. error("Cannot open file '%s'", filename);
  77. return NULL;
  78. }
  79. ff = procfile_readall(ff);
  80. if(unlikely(!ff)) {
  81. error("Cannot read file '%s'", filename);
  82. return NULL;
  83. }
  84. size_t lines = procfile_lines(ff), l;
  85. struct iface *root = NULL;
  86. for(l = 2; l < lines ;l++) {
  87. if (unlikely(procfile_linewords(ff, l) < 1)) continue;
  88. struct iface *t = callocz(1, sizeof(struct iface));
  89. t->device = strdupz(procfile_lineword(ff, l, 0));
  90. t->hash = simple_hash(t->device);
  91. t->ifindex = read_iface_ifindex(prefix, t->device);
  92. t->iflink = read_iface_iflink(prefix, t->device);
  93. t->next = root;
  94. root = t;
  95. #ifdef NETDATA_INTERNAL_CHECKS
  96. info("added %s interface '%s', ifindex %u, iflink %u", scope, t->device, t->ifindex, t->iflink);
  97. #endif
  98. }
  99. procfile_close(ff);
  100. return root;
  101. }
  102. void free_iface(struct iface *iface) {
  103. freez((void *)iface->device);
  104. freez(iface);
  105. }
  106. void free_host_ifaces(struct iface *iface) {
  107. while(iface) {
  108. struct iface *t = iface->next;
  109. free_iface(iface);
  110. iface = t;
  111. }
  112. }
  113. int iface_is_eligible(struct iface *iface) {
  114. if(iface->iflink != iface->ifindex)
  115. return 1;
  116. return 0;
  117. }
  118. int eligible_ifaces(struct iface *root) {
  119. int eligible = 0;
  120. struct iface *t;
  121. for(t = root; t ; t = t->next)
  122. if(iface_is_eligible(t))
  123. eligible++;
  124. return eligible;
  125. }
  126. static void continue_as_child(void) {
  127. pid_t child = fork();
  128. int status;
  129. pid_t ret;
  130. if (child < 0)
  131. error("fork() failed");
  132. /* Only the child returns */
  133. if (child == 0)
  134. return;
  135. for (;;) {
  136. ret = waitpid(child, &status, WUNTRACED);
  137. if ((ret == child) && (WIFSTOPPED(status))) {
  138. /* The child suspended so suspend us as well */
  139. kill(getpid(), SIGSTOP);
  140. kill(child, SIGCONT);
  141. } else {
  142. break;
  143. }
  144. }
  145. /* Return the child's exit code if possible */
  146. if (WIFEXITED(status)) {
  147. exit(WEXITSTATUS(status));
  148. } else if (WIFSIGNALED(status)) {
  149. kill(getpid(), WTERMSIG(status));
  150. }
  151. exit(EXIT_FAILURE);
  152. }
  153. int proc_pid_fd(const char *prefix, const char *ns, pid_t pid) {
  154. if(!prefix) prefix = "";
  155. char filename[FILENAME_MAX + 1];
  156. snprintfz(filename, FILENAME_MAX, "%s/proc/%d/%s", prefix, (int)pid, ns);
  157. int fd = open(filename, O_RDONLY);
  158. if(fd == -1)
  159. error("Cannot open proc_pid_fd() file '%s'", filename);
  160. return fd;
  161. }
  162. static struct ns {
  163. int nstype;
  164. int fd;
  165. int status;
  166. const char *name;
  167. const char *path;
  168. } all_ns[] = {
  169. // { .nstype = CLONE_NEWUSER, .fd = -1, .status = -1, .name = "user", .path = "ns/user" },
  170. // { .nstype = CLONE_NEWCGROUP, .fd = -1, .status = -1, .name = "cgroup", .path = "ns/cgroup" },
  171. // { .nstype = CLONE_NEWIPC, .fd = -1, .status = -1, .name = "ipc", .path = "ns/ipc" },
  172. // { .nstype = CLONE_NEWUTS, .fd = -1, .status = -1, .name = "uts", .path = "ns/uts" },
  173. { .nstype = CLONE_NEWNET, .fd = -1, .status = -1, .name = "network", .path = "ns/net" },
  174. { .nstype = CLONE_NEWPID, .fd = -1, .status = -1, .name = "pid", .path = "ns/pid" },
  175. { .nstype = CLONE_NEWNS, .fd = -1, .status = -1, .name = "mount", .path = "ns/mnt" },
  176. // terminator
  177. { .nstype = 0, .fd = -1, .status = -1, .name = NULL, .path = NULL }
  178. };
  179. int switch_namespace(const char *prefix, pid_t pid) {
  180. #ifdef HAVE_SETNS
  181. int i;
  182. for(i = 0; all_ns[i].name ; i++)
  183. all_ns[i].fd = proc_pid_fd(prefix, all_ns[i].path, pid);
  184. int root_fd = proc_pid_fd(prefix, "root", pid);
  185. int cwd_fd = proc_pid_fd(prefix, "cwd", pid);
  186. setgroups(0, NULL);
  187. // 2 passes - found it at nsenter source code
  188. // this is related CLONE_NEWUSER functionality
  189. // This code cannot switch user namespace (it can all the other namespaces)
  190. // Fortunately, we don't need to switch user namespaces.
  191. int pass;
  192. for(pass = 0; pass < 2 ;pass++) {
  193. for(i = 0; all_ns[i].name ; i++) {
  194. if (all_ns[i].fd != -1 && all_ns[i].status == -1) {
  195. if(setns(all_ns[i].fd, all_ns[i].nstype) == -1) {
  196. if(pass == 1) {
  197. all_ns[i].status = 0;
  198. error("Cannot switch to %s namespace of pid %d", all_ns[i].name, (int) pid);
  199. }
  200. }
  201. else
  202. all_ns[i].status = 1;
  203. }
  204. }
  205. }
  206. setgroups(0, NULL);
  207. if(root_fd != -1) {
  208. if(fchdir(root_fd) < 0)
  209. error("Cannot fchdir() to pid %d root directory", (int)pid);
  210. if(chroot(".") < 0)
  211. error("Cannot chroot() to pid %d root directory", (int)pid);
  212. close(root_fd);
  213. }
  214. if(cwd_fd != -1) {
  215. if(fchdir(cwd_fd) < 0)
  216. error("Cannot fchdir() to pid %d current working directory", (int)pid);
  217. close(cwd_fd);
  218. }
  219. int do_fork = 0;
  220. for(i = 0; all_ns[i].name ; i++)
  221. if(all_ns[i].fd != -1) {
  222. // CLONE_NEWPID requires a fork() to become effective
  223. if(all_ns[i].nstype == CLONE_NEWPID && all_ns[i].status)
  224. do_fork = 1;
  225. close(all_ns[i].fd);
  226. }
  227. if(do_fork)
  228. continue_as_child();
  229. return 0;
  230. #else
  231. errno = ENOSYS;
  232. error("setns() is missing on this system.");
  233. return 1;
  234. #endif
  235. }
  236. pid_t read_pid_from_cgroup_file(const char *filename) {
  237. int fd = open(filename, procfile_open_flags);
  238. if(fd == -1) {
  239. error("Cannot open pid_from_cgroup() file '%s'.", filename);
  240. return 0;
  241. }
  242. FILE *fp = fdopen(fd, "r");
  243. if(!fp) {
  244. error("Cannot upgrade fd to fp for file '%s'.", filename);
  245. return 0;
  246. }
  247. char buffer[100 + 1];
  248. pid_t pid = 0;
  249. char *s;
  250. while((s = fgets(buffer, 100, fp))) {
  251. buffer[100] = '\0';
  252. pid = atoi(s);
  253. if(pid > 0) break;
  254. }
  255. fclose(fp);
  256. #ifdef NETDATA_INTERNAL_CHECKS
  257. if(pid > 0) info("found pid %d on file '%s'", pid, filename);
  258. #endif
  259. return pid;
  260. }
  261. pid_t read_pid_from_cgroup_files(const char *path) {
  262. char filename[FILENAME_MAX + 1];
  263. snprintfz(filename, FILENAME_MAX, "%s/cgroup.procs", path);
  264. pid_t pid = read_pid_from_cgroup_file(filename);
  265. if(pid > 0) return pid;
  266. snprintfz(filename, FILENAME_MAX, "%s/tasks", path);
  267. return read_pid_from_cgroup_file(filename);
  268. }
  269. pid_t read_pid_from_cgroup(const char *path) {
  270. pid_t pid = read_pid_from_cgroup_files(path);
  271. if (pid > 0) return pid;
  272. DIR *dir = opendir(path);
  273. if (!dir) {
  274. error("cannot read directory '%s'", path);
  275. return 0;
  276. }
  277. struct dirent *de = NULL;
  278. while ((de = readdir(dir))) {
  279. if (de->d_type == DT_DIR
  280. && (
  281. (de->d_name[0] == '.' && de->d_name[1] == '\0')
  282. || (de->d_name[0] == '.' && de->d_name[1] == '.' && de->d_name[2] == '\0')
  283. ))
  284. continue;
  285. if (de->d_type == DT_DIR) {
  286. char filename[FILENAME_MAX + 1];
  287. snprintfz(filename, FILENAME_MAX, "%s/%s", path, de->d_name);
  288. pid = read_pid_from_cgroup(filename);
  289. if(pid > 0) break;
  290. }
  291. }
  292. closedir(dir);
  293. return pid;
  294. }
  295. // ----------------------------------------------------------------------------
  296. // send the result to netdata
  297. struct found_device {
  298. const char *host_device;
  299. const char *guest_device;
  300. uint32_t host_device_hash;
  301. struct found_device *next;
  302. } *detected_devices = NULL;
  303. void add_device(const char *host, const char *guest) {
  304. #ifdef NETDATA_INTERNAL_CHECKS
  305. info("adding device with host '%s', guest '%s'", host, guest);
  306. #endif
  307. uint32_t hash = simple_hash(host);
  308. if(guest && (!*guest || strcmp(host, guest) == 0))
  309. guest = NULL;
  310. struct found_device *f;
  311. for(f = detected_devices; f ; f = f->next) {
  312. if(f->host_device_hash == hash && !strcmp(host, f->host_device)) {
  313. if(guest && (!f->guest_device || !strcmp(f->host_device, f->guest_device))) {
  314. if(f->guest_device) freez((void *)f->guest_device);
  315. f->guest_device = strdupz(guest);
  316. }
  317. return;
  318. }
  319. }
  320. f = mallocz(sizeof(struct found_device));
  321. f->host_device = strdupz(host);
  322. f->host_device_hash = hash;
  323. f->guest_device = (guest)?strdupz(guest):NULL;
  324. f->next = detected_devices;
  325. detected_devices = f;
  326. }
  327. int send_devices(void) {
  328. int found = 0;
  329. struct found_device *f;
  330. for(f = detected_devices; f ; f = f->next) {
  331. found++;
  332. printf("%s %s\n", f->host_device, (f->guest_device)?f->guest_device:f->host_device);
  333. }
  334. return found;
  335. }
  336. // ----------------------------------------------------------------------------
  337. // this function should be called only **ONCE**
  338. // also it has to be the **LAST** to be called
  339. // since it switches namespaces, so after this call, everything is different!
  340. void detect_veth_interfaces(pid_t pid) {
  341. struct iface *cgroup = NULL;
  342. struct iface *host, *h, *c;
  343. host = read_proc_net_dev("host", netdata_configured_host_prefix);
  344. if(!host) {
  345. errno = 0;
  346. error("cannot read host interface list.");
  347. goto cleanup;
  348. }
  349. if(!eligible_ifaces(host)) {
  350. errno = 0;
  351. error("there are no double-linked host interfaces available.");
  352. goto cleanup;
  353. }
  354. if(switch_namespace(netdata_configured_host_prefix, pid)) {
  355. errno = 0;
  356. error("cannot switch to the namespace of pid %u", (unsigned int) pid);
  357. goto cleanup;
  358. }
  359. #ifdef NETDATA_INTERNAL_CHECKS
  360. info("switched to namespaces of pid %d", pid);
  361. #endif
  362. cgroup = read_proc_net_dev("cgroup", NULL);
  363. if(!cgroup) {
  364. errno = 0;
  365. error("cannot read cgroup interface list.");
  366. goto cleanup;
  367. }
  368. if(!eligible_ifaces(cgroup)) {
  369. errno = 0;
  370. error("there are not double-linked cgroup interfaces available.");
  371. goto cleanup;
  372. }
  373. for(h = host; h ; h = h->next) {
  374. if(iface_is_eligible(h)) {
  375. for (c = cgroup; c; c = c->next) {
  376. if(iface_is_eligible(c) && h->ifindex == c->iflink && h->iflink == c->ifindex) {
  377. add_device(h->device, c->device);
  378. }
  379. }
  380. }
  381. }
  382. cleanup:
  383. free_host_ifaces(cgroup);
  384. free_host_ifaces(host);
  385. }
  386. // ----------------------------------------------------------------------------
  387. // call the external helper
  388. #define CGROUP_NETWORK_INTERFACE_MAX_LINE 2048
  389. void call_the_helper(pid_t pid, const char *cgroup) {
  390. if(setresuid(0, 0, 0) == -1)
  391. error("setresuid(0, 0, 0) failed.");
  392. char command[CGROUP_NETWORK_INTERFACE_MAX_LINE + 1];
  393. if(cgroup)
  394. snprintfz(command, CGROUP_NETWORK_INTERFACE_MAX_LINE, "exec " PLUGINS_DIR "/cgroup-network-helper.sh --cgroup '%s'", cgroup);
  395. else
  396. snprintfz(command, CGROUP_NETWORK_INTERFACE_MAX_LINE, "exec " PLUGINS_DIR "/cgroup-network-helper.sh --pid %d", pid);
  397. info("running: %s", command);
  398. pid_t cgroup_pid;
  399. FILE *fp = mypopene(command, &cgroup_pid, environment);
  400. if(fp) {
  401. char buffer[CGROUP_NETWORK_INTERFACE_MAX_LINE + 1];
  402. char *s;
  403. while((s = fgets(buffer, CGROUP_NETWORK_INTERFACE_MAX_LINE, fp))) {
  404. trim(s);
  405. if(*s && *s != '\n') {
  406. char *t = s;
  407. while(*t && *t != ' ') t++;
  408. if(*t == ' ') {
  409. *t = '\0';
  410. t++;
  411. }
  412. if(!*s || !*t) continue;
  413. add_device(s, t);
  414. }
  415. }
  416. mypclose(fp, cgroup_pid);
  417. }
  418. else
  419. error("cannot execute cgroup-network helper script: %s", command);
  420. }
  421. int is_valid_path_symbol(char c) {
  422. switch(c) {
  423. case '/': // path separators
  424. case '\\': // needed for virsh domains \x2d1\x2dname
  425. case ' ': // space
  426. case '-': // hyphen
  427. case '_': // underscore
  428. case '.': // dot
  429. case ',': // comma
  430. return 1;
  431. default:
  432. return 0;
  433. }
  434. }
  435. // we will pass this path a shell script running as root
  436. // so, we need to make sure the path will be valid
  437. // and will not include anything that could allow
  438. // the caller use shell expansion for gaining escalated
  439. // privileges.
  440. int verify_path(const char *path) {
  441. struct stat sb;
  442. char c;
  443. const char *s = path;
  444. while((c = *s++)) {
  445. if(!( isalnum(c) || is_valid_path_symbol(c) )) {
  446. error("invalid character in path '%s'", path);
  447. return -1;
  448. }
  449. }
  450. if(strstr(path, "\\") && !strstr(path, "\\x")) {
  451. error("invalid escape sequence in path '%s'", path);
  452. return 1;
  453. }
  454. if(strstr(path, "/../")) {
  455. error("invalid parent path sequence detected in '%s'", path);
  456. return 1;
  457. }
  458. if(path[0] != '/') {
  459. error("only absolute path names are supported - invalid path '%s'", path);
  460. return -1;
  461. }
  462. if (stat(path, &sb) == -1) {
  463. error("cannot stat() path '%s'", path);
  464. return -1;
  465. }
  466. if((sb.st_mode & S_IFMT) != S_IFDIR) {
  467. error("path '%s' is not a directory", path);
  468. return -1;
  469. }
  470. return 0;
  471. }
  472. /*
  473. char *fix_path_variable(void) {
  474. const char *path = getenv("PATH");
  475. if(!path || !*path) return 0;
  476. char *p = strdupz(path);
  477. char *safe_path = callocz(1, strlen(p) + strlen("PATH=") + 1);
  478. strcpy(safe_path, "PATH=");
  479. int added = 0;
  480. char *ptr = p;
  481. while(ptr && *ptr) {
  482. char *s = strsep(&ptr, ":");
  483. if(s && *s) {
  484. if(verify_path(s) == -1) {
  485. error("the PATH variable includes an invalid path '%s' - removed it.", s);
  486. }
  487. else {
  488. info("the PATH variable includes a valid path '%s'.", s);
  489. if(added) strcat(safe_path, ":");
  490. strcat(safe_path, s);
  491. added++;
  492. }
  493. }
  494. }
  495. info("unsafe PATH: '%s'.", path);
  496. info(" safe PATH: '%s'.", safe_path);
  497. freez(p);
  498. return safe_path;
  499. }
  500. */
  501. // ----------------------------------------------------------------------------
  502. // main
  503. void usage(void) {
  504. fprintf(stderr, "%s [ -p PID | --pid PID | --cgroup /path/to/cgroup ]\n", program_name);
  505. exit(1);
  506. }
  507. int main(int argc, char **argv) {
  508. pid_t pid = 0;
  509. program_name = argv[0];
  510. program_version = VERSION;
  511. error_log_syslog = 0;
  512. // since cgroup-network runs as root, prevent it from opening symbolic links
  513. procfile_open_flags = O_RDONLY|O_NOFOLLOW;
  514. // ------------------------------------------------------------------------
  515. // make sure NETDATA_HOST_PREFIX is safe
  516. netdata_configured_host_prefix = getenv("NETDATA_HOST_PREFIX");
  517. if(verify_netdata_host_prefix() == -1) exit(1);
  518. if(netdata_configured_host_prefix[0] != '\0' && verify_path(netdata_configured_host_prefix) == -1)
  519. fatal("invalid NETDATA_HOST_PREFIX '%s'", netdata_configured_host_prefix);
  520. // ------------------------------------------------------------------------
  521. // build a safe environment for our script
  522. // the first environment variable is a fixed PATH=
  523. snprintfz(environment_variable2, sizeof(environment_variable2) - 1, "NETDATA_HOST_PREFIX=%s", netdata_configured_host_prefix);
  524. // ------------------------------------------------------------------------
  525. if(argc == 2 && (!strcmp(argv[1], "version") || !strcmp(argv[1], "-version") || !strcmp(argv[1], "--version") || !strcmp(argv[1], "-v") || !strcmp(argv[1], "-V"))) {
  526. fprintf(stderr, "cgroup-network %s\n", VERSION);
  527. exit(0);
  528. }
  529. if(argc != 3)
  530. usage();
  531. if(!strcmp(argv[1], "-p") || !strcmp(argv[1], "--pid")) {
  532. pid = atoi(argv[2]);
  533. if(pid <= 0) {
  534. errno = 0;
  535. error("Invalid pid %d given", (int) pid);
  536. return 2;
  537. }
  538. call_the_helper(pid, NULL);
  539. }
  540. else if(!strcmp(argv[1], "--cgroup")) {
  541. char *cgroup = argv[2];
  542. if(verify_path(cgroup) == -1)
  543. fatal("cgroup '%s' does not exist or is not valid.", cgroup);
  544. pid = read_pid_from_cgroup(cgroup);
  545. call_the_helper(pid, cgroup);
  546. if(pid <= 0 && !detected_devices) {
  547. errno = 0;
  548. error("Cannot find a cgroup PID from cgroup '%s'", cgroup);
  549. }
  550. }
  551. else
  552. usage();
  553. if(pid > 0)
  554. detect_veth_interfaces(pid);
  555. int found = send_devices();
  556. if(found <= 0) return 1;
  557. return 0;
  558. }