diff --git a/src/.clang-format b/src/.clang-format index 22ab0cedf..e2ca61b06 100644 --- a/src/.clang-format +++ b/src/.clang-format @@ -711,6 +711,6 @@ UseTab: Always # Infix overrides # ColumnLimit: 0 -ForEachMacros: ['LYX_LIST_FOR_EACH', 'TAILQ_FOREACH', 'LY_LIST_FOR'] +ForEachMacros: ['LYX_LIST_FOR_EACH', 'TAILQ_FOREACH', 'LY_LIST_FOR', 'json_array_foreach'] UseTab: AlignWithSpaces ... diff --git a/src/statd/statd.c b/src/statd/statd.c index c786a46c1..4c8127ca6 100644 --- a/src/statd/statd.c +++ b/src/statd/statd.c @@ -26,7 +26,7 @@ #include "shared.h" -#define SOCK_RMEM_SIZE 1000000 /* Arbitrary chosen, default = 212992 */ +#define SOCK_RMEM_SIZE 1000000 /* Arbitrary chosen, default = 212992 */ #define NL_BUF_SIZE 4096 /* Arbitrary chosen */ #define XPATH_MAX PATH_MAX @@ -43,7 +43,8 @@ struct sub { struct ev_io watcher; sr_subscription_ctx_t *sr_sub; - TAILQ_ENTRY(sub) entries; + TAILQ_ENTRY(sub) + entries; }; struct netlink { @@ -60,11 +61,11 @@ struct statd { static void set_sock_rcvbuf(int sd, int size) { - if (setsockopt(sd, SOL_SOCKET, SO_RCVBUF, &size, sizeof(size)) < 0) { - perror("setsockopt"); - return; - } - DEBUG("Socket receive buffer size increased to: %d bytes", size); + if (setsockopt(sd, SOL_SOCKET, SO_RCVBUF, &size, sizeof(size)) < 0) { + perror("setsockopt"); + return; + } + DEBUG("Socket receive buffer size increased to: %d bytes", size); } static int nl_sock_init(void) @@ -121,7 +122,7 @@ static json_t *json_get_ip_link(void) } static int ly_add_yanger_data(const struct ly_ctx *ctx, struct lyd_node **parent, - char *model, const char *arg) + char *model, const char *arg) { char *yanger_args[4] = { "/lib/infix/yanger", @@ -133,12 +134,12 @@ static int ly_add_yanger_data(const struct ly_ctx *ctx, struct lyd_node **parent int err; int fd; - if(!model) { + if (!model) { ERROR("Missing yang model to use"); return SR_ERR_SYS; } - if(!strcmp(model,"ietf-interfaces")) + if (!strcmp(model, "ietf-interfaces")) yanger_args[2] = (char *)arg; fd = memfd_create("my_temp_file", 0); @@ -172,7 +173,7 @@ static int ly_add_yanger_data(const struct ly_ctx *ctx, struct lyd_node **parent return SR_ERR_SYS; } - err = lyd_parse_data_fd(ctx, fd, LYD_JSON, LYD_PARSE_ONLY , 0, parent); + err = lyd_parse_data_fd(ctx, fd, LYD_JSON, LYD_PARSE_ONLY, 0, parent); if (err) ERROR("Error, parsing yanger data (%d)", err); @@ -183,8 +184,8 @@ static int ly_add_yanger_data(const struct ly_ctx *ctx, struct lyd_node **parent } static int sr_ifaces_cb(sr_session_ctx_t *session, uint32_t, const char *path, - const char *, const char *, uint32_t, - struct lyd_node **parent, void *priv) + const char *, const char *, uint32_t, + struct lyd_node **parent, void *priv) { struct sub *sub = priv; const struct ly_ctx *ctx; @@ -215,8 +216,8 @@ static int sr_ifaces_cb(sr_session_ctx_t *session, uint32_t, const char *path, } static int sr_routes_cb(sr_session_ctx_t *session, uint32_t, const char *path, - const char *, const char *, uint32_t, - struct lyd_node **parent, __attribute__((unused))void *priv) + const char *, const char *, uint32_t, + struct lyd_node **parent, __attribute__((unused)) void *priv) { const struct ly_ctx *ctx; sr_conn_ctx_t *con; @@ -263,15 +264,14 @@ static void sr_event_cb(struct ev_loop *, struct ev_io *w, int) } static int subscribe(struct statd *statd, char *model, char *xpath, const char *name, - int (*cb) (sr_session_ctx_t *session, uint32_t, const char *, - const char *, const char *, uint32_t, - struct lyd_node **parent, void *priv)) + int (*cb)(sr_session_ctx_t *session, uint32_t, const char *, + const char *, const char *, uint32_t, + struct lyd_node **parent, void *priv)) { - struct sub *sub; - int sr_ev_pipe; + int sr_ev_pipe; sr_error_t err; - + sub = sub_find(&statd->subs, name); if (sub) { DEBUG("%s already subscribed", name); @@ -280,7 +280,7 @@ static int subscribe(struct statd *statd, char *model, char *xpath, const char * sub = malloc(sizeof(struct sub)); memset(sub, 0, sizeof(struct sub)); - if(strlen(name) > sizeof(sub->name)) { + if (strlen(name) > sizeof(sub->name)) { ERROR("Subscriber name is to long"); return SR_ERR_INTERNAL; } @@ -288,9 +288,9 @@ static int subscribe(struct statd *statd, char *model, char *xpath, const char * DEBUG("Subscribe to events for \"%s\"", xpath); err = sr_oper_get_subscribe(statd->sr_ses, model, - xpath, cb, sub, - SR_SUBSCR_DEFAULT | SR_SUBSCR_NO_THREAD | SR_SUBSCR_DONE_ONLY, - &sub->sr_sub); + xpath, cb, sub, + SR_SUBSCR_DEFAULT | SR_SUBSCR_NO_THREAD | SR_SUBSCR_DONE_ONLY, + &sub->sr_sub); if (err) { ERROR("Error, subscribing to path \"%s\": %s", xpath, sr_strerror(err)); free(sub); @@ -335,7 +335,6 @@ static int sub_to_iface(struct statd *statd, const char *ifname) snprintf(path, sizeof(path), "%s/interface[name='%s']", XPATH_IFACE_BASE, ifname); return subscribe(statd, "ietf-interfaces", path, ifname, sr_ifaces_cb); - } static void unsub_to_all(struct statd *statd) @@ -393,7 +392,7 @@ static int nl_process_msg(struct nlmsghdr *nlh, struct statd *statd) static void nl_event_cb(struct ev_loop *, struct ev_io *w, int) { - struct statd *statd = (struct statd *) w->data; + struct statd *statd = (struct statd *)w->data; char buf[NL_BUF_SIZE]; struct nlmsghdr *nlh; int err; @@ -504,7 +503,7 @@ int main(int argc, char *argv[]) } err = sub_to_routes(&statd); - if(err) { + if (err) { ERROR("Error register for IPv4 routes"); sr_disconnect(sr_conn); return EXIT_FAILURE;