Skip to content

Commit

Permalink
ifixup
Browse files Browse the repository at this point in the history
  • Loading branch information
mattiaswal committed Nov 21, 2023
1 parent c2ff0a4 commit c72461c
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 29 deletions.
2 changes: 1 addition & 1 deletion src/.clang-format
Original file line number Diff line number Diff line change
Expand Up @@ -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
...
55 changes: 27 additions & 28 deletions src/statd/statd.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 {
Expand All @@ -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)
Expand Down Expand Up @@ -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",
Expand All @@ -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);
Expand Down Expand Up @@ -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);

Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand All @@ -280,17 +280,17 @@ 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;
}
snprintf(sub->name, sizeof(sub->name), "%s", name);

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);
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit c72461c

Please sign in to comment.