Lines 44-49
__FBSDID("$FreeBSD$");
Link Here
|
44 |
#include <sys/types.h> |
44 |
#include <sys/types.h> |
45 |
#include <sys/socket.h> |
45 |
#include <sys/socket.h> |
46 |
#include <stdarg.h> |
46 |
#include <stdarg.h> |
|
|
47 |
#include <stdatomic.h> |
47 |
#include <netgraph/ng_message.h> |
48 |
#include <netgraph/ng_message.h> |
48 |
#include <netgraph/ng_socket.h> |
49 |
#include <netgraph/ng_socket.h> |
49 |
|
50 |
|
Lines 51-57
__FBSDID("$FreeBSD$");
Link Here
|
51 |
#include "internal.h" |
52 |
#include "internal.h" |
52 |
|
53 |
|
53 |
/* Next message token value */ |
54 |
/* Next message token value */ |
54 |
static int gMsgId; |
55 |
static _Atomic(unsigned int) gMsgId; |
55 |
|
56 |
|
56 |
/* For delivering both messages and replies */ |
57 |
/* For delivering both messages and replies */ |
57 |
static int NgDeliverMsg(int cs, const char *path, |
58 |
static int NgDeliverMsg(int cs, const char *path, |
Lines 72-80
NgSendMsg(int cs, const char *path,
Link Here
|
72 |
memset(&msg, 0, sizeof(msg)); |
73 |
memset(&msg, 0, sizeof(msg)); |
73 |
msg.header.version = NG_VERSION; |
74 |
msg.header.version = NG_VERSION; |
74 |
msg.header.typecookie = cookie; |
75 |
msg.header.typecookie = cookie; |
75 |
if (++gMsgId < 0) |
76 |
msg.header.token = atomic_fetch_add(&gMsgId, 1) & INT_MAX; |
76 |
gMsgId = 1; |
|
|
77 |
msg.header.token = gMsgId; |
78 |
msg.header.flags = NGF_ORIG; |
77 |
msg.header.flags = NGF_ORIG; |
79 |
msg.header.cmd = cmd; |
78 |
msg.header.cmd = cmd; |
80 |
snprintf((char *)msg.header.cmdstr, NG_CMDSTRSIZ, "cmd%d", cmd); |
79 |
snprintf((char *)msg.header.cmdstr, NG_CMDSTRSIZ, "cmd%d", cmd); |
Lines 143-151
NgSendAsciiMsg(int cs, const char *path, const char *fmt, ...)
Link Here
|
143 |
|
142 |
|
144 |
/* Now send binary version */ |
143 |
/* Now send binary version */ |
145 |
binary = (struct ng_mesg *)reply->data; |
144 |
binary = (struct ng_mesg *)reply->data; |
146 |
if (++gMsgId < 0) |
145 |
binary->header.token = atomic_fetch_add(&gMsgId, 1) & INT_MAX; |
147 |
gMsgId = 1; |
|
|
148 |
binary->header.token = gMsgId; |
149 |
binary->header.version = NG_VERSION; |
146 |
binary->header.version = NG_VERSION; |
150 |
if (NgDeliverMsg(cs, |
147 |
if (NgDeliverMsg(cs, |
151 |
path, binary, binary->data, binary->header.arglen) < 0) { |
148 |
path, binary, binary->data, binary->header.arglen) < 0) { |