system.c 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  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. #include "netifd.h"
  15. #include "system.h"
  16. #include <fcntl.h>
  17. static const struct blobmsg_policy tunnel_attrs[__TUNNEL_ATTR_MAX] = {
  18. [TUNNEL_ATTR_TYPE] = { .name = "mode", .type = BLOBMSG_TYPE_STRING },
  19. [TUNNEL_ATTR_LOCAL] = { .name = "local", .type = BLOBMSG_TYPE_STRING },
  20. [TUNNEL_ATTR_REMOTE] = { .name = "remote", .type = BLOBMSG_TYPE_STRING },
  21. [TUNNEL_ATTR_MTU] = { .name = "mtu", .type = BLOBMSG_TYPE_INT32 },
  22. [TUNNEL_ATTR_DF] = { .name = "df", .type = BLOBMSG_TYPE_BOOL },
  23. [TUNNEL_ATTR_TTL] = { .name = "ttl", .type = BLOBMSG_TYPE_INT32 },
  24. [TUNNEL_ATTR_TOS] = { .name = "tos", .type = BLOBMSG_TYPE_STRING },
  25. [TUNNEL_ATTR_LINK] = { .name = "link", .type = BLOBMSG_TYPE_STRING },
  26. [TUNNEL_ATTR_DATA] = { .name = "data", .type = BLOBMSG_TYPE_TABLE },
  27. };
  28. const struct uci_blob_param_list tunnel_attr_list = {
  29. .n_params = __TUNNEL_ATTR_MAX,
  30. .params = tunnel_attrs,
  31. };
  32. static const struct blobmsg_policy vxlan_data_attrs[__VXLAN_DATA_ATTR_MAX] = {
  33. [VXLAN_DATA_ATTR_ID] = { .name = "id", .type = BLOBMSG_TYPE_INT32 },
  34. [VXLAN_DATA_ATTR_PORT] = { .name = "port", .type = BLOBMSG_TYPE_INT32 },
  35. [VXLAN_DATA_ATTR_MACADDR] = { .name = "macaddr", .type = BLOBMSG_TYPE_STRING },
  36. [VXLAN_DATA_ATTR_RXCSUM] = { .name = "rxcsum", .type = BLOBMSG_TYPE_BOOL },
  37. [VXLAN_DATA_ATTR_TXCSUM] = { .name = "txcsum", .type = BLOBMSG_TYPE_BOOL },
  38. };
  39. const struct uci_blob_param_list vxlan_data_attr_list = {
  40. .n_params = __VXLAN_DATA_ATTR_MAX,
  41. .params = vxlan_data_attrs,
  42. };
  43. static const struct blobmsg_policy gre_data_attrs[__GRE_DATA_ATTR_MAX] = {
  44. [GRE_DATA_IKEY] = { .name = "ikey", .type = BLOBMSG_TYPE_INT32 },
  45. [GRE_DATA_OKEY] = { .name = "okey", .type = BLOBMSG_TYPE_INT32 },
  46. [GRE_DATA_ICSUM] = { .name = "icsum", .type = BLOBMSG_TYPE_BOOL },
  47. [GRE_DATA_OCSUM] = { .name = "ocsum", .type = BLOBMSG_TYPE_BOOL },
  48. [GRE_DATA_ISEQNO] = { .name = "iseqno", .type = BLOBMSG_TYPE_BOOL },
  49. [GRE_DATA_OSEQNO] = { .name = "oseqno", .type = BLOBMSG_TYPE_BOOL },
  50. };
  51. const struct uci_blob_param_list gre_data_attr_list = {
  52. .n_params = __GRE_DATA_ATTR_MAX,
  53. .params = gre_data_attrs,
  54. };
  55. static const struct blobmsg_policy vti_data_attrs[__VTI_DATA_ATTR_MAX] = {
  56. [VTI_DATA_IKEY] = { .name = "ikey", .type = BLOBMSG_TYPE_INT32 },
  57. [VTI_DATA_OKEY] = { .name = "okey", .type = BLOBMSG_TYPE_INT32 },
  58. };
  59. const struct uci_blob_param_list vti_data_attr_list = {
  60. .n_params = __VTI_DATA_ATTR_MAX,
  61. .params = vti_data_attrs,
  62. };
  63. static const struct blobmsg_policy sixrd_data_attrs[__SIXRD_DATA_ATTR_MAX] = {
  64. [SIXRD_DATA_PREFIX] = { .name = "prefix", .type = BLOBMSG_TYPE_STRING },
  65. [SIXRD_DATA_RELAY_PREFIX] = { .name = "relay-prefix", .type = BLOBMSG_TYPE_STRING },
  66. };
  67. const struct uci_blob_param_list sixrd_data_attr_list = {
  68. .n_params = __SIXRD_DATA_ATTR_MAX,
  69. .params = sixrd_data_attrs,
  70. };
  71. static const struct blobmsg_policy ipip6_data_attrs[__SIXRD_DATA_ATTR_MAX] = {
  72. [IPIP6_DATA_ENCAPLIMIT] = { .name = "encaplimit", .type = BLOBMSG_TYPE_STRING },
  73. [IPIP6_DATA_FMRS] = { .name = "fmrs", .type = BLOBMSG_TYPE_ARRAY },
  74. };
  75. const struct uci_blob_param_list ipip6_data_attr_list = {
  76. .n_params = __IPIP6_DATA_ATTR_MAX,
  77. .params = ipip6_data_attrs,
  78. };
  79. static const struct blobmsg_policy fmr_data_attrs[__FMR_DATA_ATTR_MAX] = {
  80. [FMR_DATA_PREFIX6] = { .name = "prefix6", .type = BLOBMSG_TYPE_STRING },
  81. [FMR_DATA_PREFIX4] = { .name = "prefix4", .type = BLOBMSG_TYPE_STRING },
  82. [FMR_DATA_EALEN] = { .name = "ealen", .type = BLOBMSG_TYPE_INT32 },
  83. [FMR_DATA_OFFSET] = { .name = "offset", .type = BLOBMSG_TYPE_INT32 },
  84. };
  85. const struct uci_blob_param_list fmr_data_attr_list = {
  86. .n_params = __FMR_DATA_ATTR_MAX,
  87. .params = fmr_data_attrs,
  88. };
  89. void system_fd_set_cloexec(int fd)
  90. {
  91. #ifdef FD_CLOEXEC
  92. fcntl(fd, F_SETFD, fcntl(fd, F_GETFD) | FD_CLOEXEC);
  93. #endif
  94. }