netifd.h 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. /*
  2. * netifd - network interface daemon
  3. * Copyright (C) 2012 Felix Fietkau <nbd@openwrt.org>
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License version 2
  7. * as published by the Free Software Foundation
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. */
  14. #ifndef __NETIFD_H
  15. #define __NETIFD_H
  16. #include <sys/socket.h>
  17. #include <net/if.h>
  18. #include <stdbool.h>
  19. #include <stdio.h>
  20. #include <libubox/uloop.h>
  21. #include <libubox/ustream.h>
  22. #include <libubox/utils.h>
  23. #include <libubus.h>
  24. #include "utils.h"
  25. #ifdef DUMMY_MODE
  26. #define DEFAULT_MAIN_PATH "./examples"
  27. #define DEFAULT_CONFIG_PATH "./config"
  28. #define DEFAULT_HOTPLUG_PATH "./examples/hotplug-cmd"
  29. #define DEFAULT_RESOLV_CONF "./tmp/resolv.conf"
  30. #else
  31. #define DEFAULT_MAIN_PATH "/lib/netifd"
  32. #define DEFAULT_CONFIG_PATH NULL /* use the default set in libuci */
  33. #define DEFAULT_HOTPLUG_PATH "/sbin/hotplug-call"
  34. #define DEFAULT_RESOLV_CONF "/tmp/resolv.conf.auto"
  35. #endif
  36. extern const char *resolv_conf;
  37. extern char *hotplug_cmd_path;
  38. extern unsigned int debug_mask;
  39. enum {
  40. L_CRIT,
  41. L_WARNING,
  42. L_NOTICE,
  43. L_INFO,
  44. L_DEBUG
  45. };
  46. enum {
  47. DEBUG_SYSTEM = 0,
  48. DEBUG_DEVICE = 1,
  49. DEBUG_INTERFACE = 2,
  50. DEBUG_WIRELESS = 3,
  51. };
  52. #ifdef DEBUG
  53. #define DPRINTF(format, ...) fprintf(stderr, "%s(%d): " format, __func__, __LINE__, ## __VA_ARGS__)
  54. #define D(level, format, ...) do { \
  55. if (debug_mask & (1 << (DEBUG_ ## level))) \
  56. DPRINTF(format, ##__VA_ARGS__); \
  57. } while (0)
  58. #else
  59. #define DPRINTF(format, ...) no_debug(0, format, ## __VA_ARGS__)
  60. #define D(level, format, ...) no_debug(DEBUG_ ## level, format, ## __VA_ARGS__)
  61. #endif
  62. #define LOG_BUF_SIZE 256
  63. static inline void no_debug(int level, const char *fmt, ...)
  64. {
  65. }
  66. struct netifd_process {
  67. struct list_head list;
  68. struct uloop_process uloop;
  69. void (*cb)(struct netifd_process *, int ret);
  70. int dir_fd;
  71. struct ustream_fd log;
  72. const char *log_prefix;
  73. bool log_overflow;
  74. };
  75. void netifd_log_message(int priority, const char *format, ...);
  76. int netifd_start_process(const char **argv, char **env, struct netifd_process *proc);
  77. void netifd_kill_process(struct netifd_process *proc);
  78. struct device;
  79. struct interface;
  80. extern const char *main_path;
  81. extern const char *config_path;
  82. void netifd_restart(void);
  83. void netifd_reload(void);
  84. #endif