static void* fwp_vres_tx_thread(void *_vres);
typedef enum {
- USED,
UNTOUCHED,
CHANGED,
QUEUED,
* of vres parameters. */
int ac_sockd;
/** Queue for messages to send */
- struct fwp_msgq msg_queue;
-};
-
-typedef
-struct fwp_vres_table {
- unsigned int max_vres;
- fwp_vres_t *entry;
- pthread_mutex_t lock;
-} fwp_vres_table_t;
-
-/* Global variable - vres table */
-static fwp_vres_table_t fwp_vres_table = {
- .max_vres = 0,
- .entry = NULL,
- .lock = PTHREAD_MUTEX_INITIALIZER,
+ struct fwp_msgq msg_queue;
+ /** If true, it is always allowed to send messages through this vres. */
+ bool bypass;
};
/**< mapping priority to ac*/
static inline void fwp_vres_free(fwp_vres_t *vres)
{
- /* Clear USED flag */
- clear_all_flags(vres);
-}
-
-static inline int fwp_vres_is_valid(fwp_vres_t *vres)
-{
- int id = vres - fwp_vres_table.entry;
-
- if ((id < 0) || (id > fwp_vres_table.max_vres - 1) ||
- (!get_flag(vres, USED)))
- return 0;
-
- return 1;
+ free(vres);
}
/*inline int fwp_vres_get(fwp_vres_id_t vres_id, fwp_vres_t **vres )
}
*/
-int fwp_vres_table_init(unsigned int max_vres)
-{
- unsigned int table_size = max_vres * sizeof(fwp_vres_t);
-
- fwp_vres_table.entry = (fwp_vres_t*) malloc(table_size);
- if (!fwp_vres_table.entry)
- return -1; /* Errno is set by malloc */
-
- memset((void*) fwp_vres_table.entry, 0, table_size);
- fwp_vres_table.max_vres = max_vres;
- return 0;
-}
-
/**
* Allocate vres
*
*/
fwp_vres_t *fwp_vres_alloc()
{
- int i;
- unsigned int max_vres;
-
- /* find free vres id */
- pthread_mutex_lock(&fwp_vres_table.lock);
- i = 0;
- max_vres = fwp_vres_table.max_vres;
- while ((i < max_vres) &&
- (get_flag(&fwp_vres_table.entry[i], USED))) {
- i++;
+ fwp_vres_t *vres = malloc(sizeof(*vres));
+ if (vres) {
+ memset(vres, 0, sizeof(*vres));
+ FWP_DEBUG("Allocated vres\n");
}
-
- if (i == max_vres) {
- pthread_mutex_unlock(&fwp_vres_table.lock);
- errno = ENOBUFS;
- return NULL;
- }
-
- FWP_DEBUG("Allocated vres id = %d\n",i);
- set_flag(&fwp_vres_table.entry[i], USED);
- pthread_mutex_unlock(&fwp_vres_table.lock);
- return (&fwp_vres_table.entry[i]);
+ return vres;
}
static int apply_params(fwp_vres_t *vres)
{
- int rv;
+ int rv = 0;
vres->period = vres->params.period;
vres->budget = vres->params.budget;
set_flag(vres, UNTOUCHED);
{
int rv = 0;
- if (!fwp_vres_is_valid(vres)) {
+ if (!vres) {
errno = EINVAL;
return -1;
}
* \param[in] params Vres parameters
* \param[out] vresp Pointer to the descriptor of newly created vres
*
- * \return On success returns descriptor of vres.
- * On error, negative error code is returned.
- *
+ * \return Zero on success, -1 on error and errno is set
+ * appropriately.
*/
int fwp_vres_create(fwp_vres_params_t *params, fwp_vres_t **vresp)
{
apply_params(vres);
fwp_msgq_init(&vres->msg_queue);
+ if (getenv("FWP_BYPASS"))
+ vres->bypass = true;
+
pthread_attr_init(&vres->tx_thread_attr);
if ((rv = pthread_create(&vres->tx_thread, &vres->tx_thread_attr,
fwp_vres_tx_thread, (void*) vres)) != 0){
*
* \param[in] vres Vres descriptor
*
- * \return On success returns 0.
- * On error, negative error code is returned.
- *
+ * \return Zero on success, -1 on error and errno is set
+ * appropriately.
*/
int fwp_vres_destroy(fwp_vres_t *vres)
{
- if (!fwp_vres_is_valid(vres)) {
+ if (!vres) {
errno = EINVAL;
return -1;
}
int __consume_budget(struct fwp_vres *vres, size_t size, bool can_block)
{
int ret = 0;
+ if (vres->bypass)
+ return 0;
if (vres->params.budget < size) {
errno = ENOSR;
return -1;
}
/*int fwp_vres_bind(fwp_vres_t *vres, struct fwp_endpoint *epoint)*/
-int fwp_vres_bind(fwp_vres_t *vres, struct fwp_endpoint *ep, int sockd)
+int fwp_vres_bind(fwp_vres_t *vres, struct fwp_endpoint *ep, int sockd, struct in_addr *src)
{
int rv = 0;
- if (!fwp_vres_is_valid(vres)) {
+ if (!vres) {
errno = EINVAL;
rv = -1;
goto err;
}
vres->ac_sockd = sockd;
+ *src = vres->params.src;
rv = fwp_vres_set_ac(vres->ac_sockd, vres->params.ac_id);
if (rv)
goto err;
int fwp_vres_unbind(fwp_vres_t *vres)
{
- if (!fwp_vres_is_valid(vres)) {
+ if (!vres) {
errno = EINVAL;
return -1;
}