Skip to content

Commit

Permalink
move macros
Browse files Browse the repository at this point in the history
  • Loading branch information
sreimers committed Dec 12, 2024
1 parent c7179de commit 3ac7ded
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 27 deletions.
16 changes: 1 addition & 15 deletions src/net/linux/addrs.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,26 +8,12 @@
#include <re_fmt.h>
#include <re_sa.h>
#include <re_net.h>
#include "macros.h"

#define DEBUG_MODULE "linuxaddrs"
#define DEBUG_LEVEL 5
#include <re_dbg.h>

/* Override macros to avoid casting alignment warning */
#undef RTM_RTA
#define RTM_RTA(r) (void *)(((char *)(r)) + NLMSG_ALIGN(sizeof(struct rtmsg)))
#undef RTA_NEXT
#define RTA_NEXT(rta, len) \
((len) -= RTA_ALIGN((rta)->rta_len), \
(void *)(((char *)(rta)) + RTA_ALIGN((rta)->rta_len)))
#undef NLMSG_NEXT
#define NLMSG_NEXT(nlh, len) \
((len) -= NLMSG_ALIGN((nlh)->nlmsg_len), \
(void *)(((char *)(nlh)) + NLMSG_ALIGN((nlh)->nlmsg_len)))
#undef IFA_RTA
#define IFA_RTA(r) \
((void *)(((char *)(r)) + NLMSG_ALIGN(sizeof(struct ifaddrmsg))))


static void parse_rtattr(struct rtattr *tb[], struct rtattr *rta, int len)
{
Expand Down
14 changes: 14 additions & 0 deletions src/net/linux/macros.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/* Override macros to avoid casting alignment warning */
#undef RTM_RTA
#define RTM_RTA(r) (void *)(((char *)(r)) + NLMSG_ALIGN(sizeof(struct rtmsg)))
#undef RTA_NEXT
#define RTA_NEXT(rta, len) \
((len) -= RTA_ALIGN((rta)->rta_len), \
(void *)(((char *)(rta)) + RTA_ALIGN((rta)->rta_len)))
#undef NLMSG_NEXT
#define NLMSG_NEXT(nlh, len) \
((len) -= NLMSG_ALIGN((nlh)->nlmsg_len), \
(void *)(((char *)(nlh)) + NLMSG_ALIGN((nlh)->nlmsg_len)))
#undef IFA_RTA
#define IFA_RTA(r) \
((void *)(((char *)(r)) + NLMSG_ALIGN(sizeof(struct ifaddrmsg))))
13 changes: 1 addition & 12 deletions src/net/linux/rt.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,24 +15,13 @@
#include <re_fmt.h>
#include <re_sa.h>
#include <re_net.h>
#include "macros.h"


#define DEBUG_MODULE "linuxrt"
#define DEBUG_LEVEL 5
#include <re_dbg.h>


/* Override macros to avoid casting alignment warning */
#undef RTM_RTA
#define RTM_RTA(r) (void *)(((char *)(r)) + NLMSG_ALIGN(sizeof(struct rtmsg)))
#undef RTA_NEXT
#define RTA_NEXT(rta, len) ((len) -= RTA_ALIGN((rta)->rta_len), \
(void *)(((char *)(rta)) + RTA_ALIGN((rta)->rta_len)))
#undef NLMSG_NEXT
#define NLMSG_NEXT(nlh,len) ((len) -= NLMSG_ALIGN((nlh)->nlmsg_len), \
(void*)(((char*)(nlh)) + NLMSG_ALIGN((nlh)->nlmsg_len)))


enum {BUFSIZE = 8192};


Expand Down

0 comments on commit 3ac7ded

Please sign in to comment.