In the splnet(9) times netgraph(4) was synchronous and if a message

had been replied, the reply was always delivered to the originator
synchronously.

With introduction of netgraph item callbacks and a wait channel with
mutex in ng_socket(4), we have fixed the problem with ngctl(8) returning
earlier than the command has been proceeded by target node. But still
ngctl(8) can return prior to the reply has arrived to its node.

To fix this:
 - Introduce a new flag for netgraph(4) messages - NGM_HASREPLY.
   This flag is or'ed with message like NGM_READONLY.
 - In netgraph userland library if we have sent a message with
   NGM_HASREPLY flag, then select(2) until reply comes.
 - Mark appropriate generic commands with NGM_HASREPLY flag,
   gathering them into one enum {}. Bump generic cookie.
This commit is contained in:
Gleb Smirnoff 2006-01-12 19:14:40 +00:00
parent 352219015d
commit 2df050ad10
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=154265
2 changed files with 47 additions and 17 deletions

View File

@ -232,6 +232,22 @@ NgDeliverMsg(int cs, const char *path,
goto done;
}
/* Wait for reply if there should be one. */
if (msg->header.cmd & NGM_HASREPLY) {
fd_set rfds;
int n;
FD_ZERO(&rfds);
FD_SET(cs, &rfds);
n = select(cs + 1, &rfds, NULL, NULL, NULL);
if (n == -1) {
errnosv = errno;
if (_gNgDebugLevel >= 1)
NGLOG("select");
rtn = -1;
}
}
done:
/* Done */
free(buf); /* OK if buf is NULL */

View File

@ -78,8 +78,10 @@ struct ng_mesg {
char data[]; /* placeholder for actual data */
};
/* this command is guaranteed to not alter data or'd into the command */
/* This command is guaranteed to not alter data (or'd into the command). */
#define NGM_READONLY 0x10000000
/* This command is guaranteed to have a reply (or'd into the command). */
#define NGM_HASREPLY 0x20000000
/* Keep this in sync with the above structure definition */
#define NG_GENERIC_NG_MESG_INFO(dtype) { \
@ -117,23 +119,35 @@ struct ng_mesg {
*/
/* Generic message type cookie */
#define NGM_GENERIC_COOKIE 977674408
#define NGM_GENERIC_COOKIE 1137070366
/* Generic messages defined for this type cookie */
#define NGM_SHUTDOWN 1 /* shut down node */
#define NGM_MKPEER 2 /* create and attach a peer node */
#define NGM_CONNECT 3 /* connect two nodes */
#define NGM_NAME 4 /* give a node a name */
#define NGM_RMHOOK 5 /* break a connection btw. two nodes */
#define NGM_NODEINFO (6|NGM_READONLY)/* get nodeinfo for target */
#define NGM_LISTHOOKS (7|NGM_READONLY)/* get list of hooks on node */
#define NGM_LISTNAMES (8|NGM_READONLY)/* list globally named nodes */
#define NGM_LISTNODES (9|NGM_READONLY)/* list nodes, named & not */
#define NGM_LISTTYPES (10|NGM_READONLY)/* list installed node types */
#define NGM_TEXT_STATUS (11|NGM_READONLY)/* (optional) get txt status */
#define NGM_BINARY2ASCII (12|NGM_READONLY)/* convert ng_mesg to ascii */
#define NGM_ASCII2BINARY (13|NGM_READONLY)/* convert ascii to ng_mesg */
#define NGM_TEXT_CONFIG 14 /* (optional) get/set text config */
/* Generic messages defined for this type cookie. */
enum {
NGM_SHUTDOWN = 1, /* Shut down node. */
NGM_MKPEER = 2, /* Create and attach a peer node. */
NGM_CONNECT = 3, /* Connect two nodes. */
NGM_NAME = 4, /* Give a node a name. */
NGM_RMHOOK = 5, /* Break a connection between two nodes. */
/* Get nodeinfo for target. */
NGM_NODEINFO = (6|NGM_READONLY|NGM_HASREPLY),
/* Get list of hooks on node. */
NGM_LISTHOOKS = (7|NGM_READONLY|NGM_HASREPLY),
/* List globally named nodes. */
NGM_LISTNAMES = (8|NGM_READONLY|NGM_HASREPLY),
/* List all nodes. */
NGM_LISTNODES = (9|NGM_READONLY|NGM_HASREPLY),
/* List installed node types. */
NGM_LISTTYPES = (10|NGM_READONLY|NGM_HASREPLY),
/* (optional) Get text status. */
NGM_TEXT_STATUS = (11|NGM_READONLY|NGM_HASREPLY),
/* Convert struct ng_mesg to ASCII. */
NGM_BINARY2ASCII= (12|NGM_READONLY|NGM_HASREPLY),
/* Convert ASCII to struct ng_mesg. */
NGM_ASCII2BINARY= (13|NGM_READONLY|NGM_HASREPLY),
/* (optional) Get/set text config. */
NGM_TEXT_CONFIG = 14,
};
/*
* Flow control and intra node control messages.