Cleanups to Macros for sending data between netgraph nodes.
This commit is contained in:
parent
9a72858cee
commit
a3c4c7524d
@ -837,37 +837,18 @@ _ngi_hook(item_p item, char *file, int line)
|
|||||||
/**********************************************************************
|
/**********************************************************************
|
||||||
* Data macros. Send, manipulate and free.
|
* Data macros. Send, manipulate and free.
|
||||||
**********************************************************************/
|
**********************************************************************/
|
||||||
/* Send previously unpackeged data and metadata. */
|
/*
|
||||||
#define NG_SEND_DATA(error, hook, m, meta) \
|
* Assuming the data is already ok, just set the new address and send
|
||||||
|
*/
|
||||||
|
#define NG_FWD_ITEM_HOOK(error, item, hook) \
|
||||||
do { \
|
do { \
|
||||||
item_p item; \
|
(error) = \
|
||||||
if ((item = ng_package_data((m), (meta)))) { \
|
ng_address_hook(NULL, (item), (hook), NULL); \
|
||||||
if (!((error) = ng_address_hook(NULL, item, \
|
if (error == 0) { \
|
||||||
hook, NULL))) { \
|
SAVE_LINE(item); \
|
||||||
SAVE_LINE(item); \
|
(error) = ng_snd_item((item), 0); \
|
||||||
(error) = ng_snd_item((item), 0); \
|
|
||||||
} \
|
|
||||||
} else { \
|
|
||||||
(error) = ENOMEM; \
|
|
||||||
} \
|
} \
|
||||||
(m) = NULL; \
|
(item) = NULL; \
|
||||||
(meta) = NULL; \
|
|
||||||
} while (0)
|
|
||||||
|
|
||||||
/* Send a previously unpackaged mbuf when we have no metadata to send */
|
|
||||||
#define NG_SEND_DATA_ONLY(error, hook, m) \
|
|
||||||
do { \
|
|
||||||
item_p item; \
|
|
||||||
if ((item = ng_package_data((m), NULL))) { \
|
|
||||||
if (!((error) = ng_address_hook(NULL, item, \
|
|
||||||
hook, NULL))) { \
|
|
||||||
SAVE_LINE(item); \
|
|
||||||
(error) = ng_snd_item((item), 0); \
|
|
||||||
} \
|
|
||||||
} else { \
|
|
||||||
(error) = ENOMEM; \
|
|
||||||
} \
|
|
||||||
(m) = NULL; \
|
|
||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -880,35 +861,40 @@ _ngi_hook(item_p item, char *file, int line)
|
|||||||
*/
|
*/
|
||||||
#define NG_FWD_NEW_DATA(error, item, hook, m) \
|
#define NG_FWD_NEW_DATA(error, item, hook, m) \
|
||||||
do { \
|
do { \
|
||||||
NGI_M(item) = m; \
|
NGI_M(item) = (m); \
|
||||||
if (!((error) = ng_address_hook(NULL, (item), \
|
(m) = NULL; \
|
||||||
(hook), NULL))) { \
|
NG_FWD_ITEM_HOOK(error, item, hook); \
|
||||||
SAVE_LINE(item); \
|
} while (0)
|
||||||
(error) = ng_snd_item((item), 0); \
|
|
||||||
|
/* Send a previously unpackaged mbuf when we have no metadata to send */
|
||||||
|
#define NG_SEND_DATA_ONLY(error, hook, m) \
|
||||||
|
do { \
|
||||||
|
item_p item; \
|
||||||
|
if ((item = ng_package_data((m), NULL))) { \
|
||||||
|
NG_FWD_ITEM_HOOK(error, item, hook); \
|
||||||
|
} else { \
|
||||||
|
(error) = ENOMEM; \
|
||||||
} \
|
} \
|
||||||
(item) = NULL; \
|
|
||||||
(m) = NULL; \
|
(m) = NULL; \
|
||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
/*
|
/* Send previously unpackeged data and metadata. */
|
||||||
* Assuming the data is already ok, just set the new address and send
|
#define NG_SEND_DATA(error, hook, m, meta) \
|
||||||
*/
|
|
||||||
#define NG_FWD_ITEM_HOOK(error, item, hook) \
|
|
||||||
do { \
|
do { \
|
||||||
if (!((error) = ng_address_hook(NULL, (item), \
|
item_p item; \
|
||||||
(hook), NULL))) { \
|
if ((item = ng_package_data((m), (meta)))) { \
|
||||||
SAVE_LINE(item); \
|
NG_FWD_ITEM_HOOK(error, item, hook); \
|
||||||
(error) = ng_snd_item((item), 0); \
|
|
||||||
} else { \
|
} else { \
|
||||||
(error) = ENXIO; \
|
(error) = ENOMEM; \
|
||||||
} \
|
} \
|
||||||
(item) = NULL; \
|
(m) = NULL; \
|
||||||
|
(meta) = NULL; \
|
||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
#define NG_FREE_MSG(msg) \
|
#define NG_FREE_MSG(msg) \
|
||||||
do { \
|
do { \
|
||||||
if ((msg)) { \
|
if ((msg)) { \
|
||||||
FREE((msg), M_NETGRAPH_MSG); \
|
FREE((msg), M_NETGRAPH_MSG); \
|
||||||
(msg) = NULL; \
|
(msg) = NULL; \
|
||||||
} \
|
} \
|
||||||
} while (0)
|
} while (0)
|
||||||
@ -981,22 +967,6 @@ _ngi_hook(item_p item, char *file, int line)
|
|||||||
(msg) = NULL; \
|
(msg) = NULL; \
|
||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
#define NG_QUEUE_MSG(error, here, msg, path, retaddr) \
|
|
||||||
do { \
|
|
||||||
item_p item; \
|
|
||||||
if ((item = ng_package_msg(msg)) == NULL) { \
|
|
||||||
(msg) = NULL; \
|
|
||||||
(error) = ENOMEM; \
|
|
||||||
break; \
|
|
||||||
} \
|
|
||||||
if (((error) = ng_address_path((here), (item), \
|
|
||||||
(path), (retaddr))) == 0) { \
|
|
||||||
SAVE_LINE(item); \
|
|
||||||
(error) = ng_snd_item((item), 1); \
|
|
||||||
} \
|
|
||||||
(msg) = NULL; \
|
|
||||||
} while (0)
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Redirect the message to the next hop using the given hook.
|
* Redirect the message to the next hop using the given hook.
|
||||||
* ng_retarget_msg() frees the item if there is an error
|
* ng_retarget_msg() frees the item if there is an error
|
||||||
|
@ -3602,7 +3602,6 @@ ng_macro_test(item_p item)
|
|||||||
NG_SEND_MSG_HOOK(error, node, msg, hook, retaddr);
|
NG_SEND_MSG_HOOK(error, node, msg, hook, retaddr);
|
||||||
NG_SEND_MSG_ID(error, node, msg, retaddr, retaddr);
|
NG_SEND_MSG_ID(error, node, msg, retaddr, retaddr);
|
||||||
NG_SEND_MSG_PATH(error, node, msg, ".:", retaddr);
|
NG_SEND_MSG_PATH(error, node, msg, ".:", retaddr);
|
||||||
NG_QUEUE_MSG(error, node, msg, ".:", retaddr);
|
|
||||||
NG_FWD_MSG_HOOK(error, node, item, hook, retaddr);
|
NG_FWD_MSG_HOOK(error, node, item, hook, retaddr);
|
||||||
}
|
}
|
||||||
#endif /* TESTING */
|
#endif /* TESTING */
|
||||||
|
Loading…
Reference in New Issue
Block a user