netifd.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  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 <udebug.h>
  25. #ifdef linux
  26. #include <netinet/ether.h>
  27. #else
  28. #include <net/ethernet.h>
  29. #endif
  30. #include "utils.h"
  31. #ifdef DUMMY_MODE
  32. #define DEFAULT_MAIN_PATH "./examples"
  33. #define DEFAULT_CONFIG_PATH "./config"
  34. #define DEFAULT_HOTPLUG_PATH "./examples/hotplug-cmd"
  35. #define DEFAULT_RESOLV_CONF "./tmp/resolv.conf"
  36. #define DEFAULT_BOARD_JSON "./config/board.json"
  37. #else
  38. #define DEFAULT_MAIN_PATH "/lib/netifd"
  39. #define DEFAULT_CONFIG_PATH NULL /* use the default set in libuci */
  40. #define DEFAULT_HOTPLUG_PATH "/sbin/hotplug-call"
  41. #define DEFAULT_RESOLV_CONF "/tmp/resolv.conf.d/resolv.conf.auto"
  42. #define DEFAULT_BOARD_JSON "/etc/board.json"
  43. #endif
  44. extern const char *resolv_conf;
  45. extern char *hotplug_cmd_path;
  46. extern unsigned int debug_mask;
  47. extern struct udebug_buf udb_nl;
  48. enum {
  49. L_CRIT,
  50. L_WARNING,
  51. L_NOTICE,
  52. L_INFO,
  53. L_DEBUG
  54. };
  55. enum {
  56. DEBUG_SYSTEM = 0,
  57. DEBUG_DEVICE = 1,
  58. DEBUG_INTERFACE = 2,
  59. DEBUG_WIRELESS = 3,
  60. };
  61. #ifdef DEBUG
  62. #define DPRINTF(format, ...) fprintf(stderr, "%s(%d): " format, __func__, __LINE__, ## __VA_ARGS__)
  63. #define D(level, format, ...) do { \
  64. netifd_udebug_printf("[" #level "] %s(%d): " format, __func__, __LINE__, ## __VA_ARGS__); \
  65. if (debug_mask & (1 << (DEBUG_ ## level))) { \
  66. DPRINTF(format, ##__VA_ARGS__); \
  67. fprintf(stderr, "\n"); \
  68. } \
  69. } while (0)
  70. #else
  71. #define DPRINTF(format, ...) no_debug(0, format, ## __VA_ARGS__)
  72. #define D(level, format, ...) no_debug(DEBUG_ ## level, format, ## __VA_ARGS__)
  73. #endif
  74. #define LOG_BUF_SIZE 256
  75. static inline void no_debug(int level, const char *fmt, ...)
  76. {
  77. }
  78. struct netifd_process {
  79. struct list_head list;
  80. struct uloop_process uloop;
  81. void (*cb)(struct netifd_process *, int ret);
  82. int dir_fd;
  83. struct ustream_fd log;
  84. const char *log_prefix;
  85. bool log_overflow;
  86. };
  87. void netifd_udebug_printf(const char *format, ...);
  88. void netifd_udebug_config(struct udebug_ubus *ctx, struct blob_attr *data,
  89. bool enabled);
  90. void netifd_log_message(int priority, const char *format, ...);
  91. int netifd_start_process(const char **argv, char **env, struct netifd_process *proc);
  92. void netifd_kill_process(struct netifd_process *proc);
  93. struct device;
  94. struct interface;
  95. extern const char *main_path;
  96. extern const char *config_path;
  97. void netifd_restart(void);
  98. int netifd_reload(void);
  99. #endif