struct fwp_msgq tx_queue;
int flags;
/**< endpoint bounded to this vres */
- fwp_endpoint_d_t epointd;
+ fwp_endpoint_t *epoint;
pthread_t tx_thread; /**< tx_thread id*/
pthread_attr_t tx_thread_attr;
int ac_sockd; /**< ac socket descriptor */
static const int prio_to_ac[8] = {2,3,3,2,1,1,0,0};
static const unsigned int ac_to_tos[4] = {224,160,96,64};
+static inline int fwp_vres_set_ac(int sockd, fwp_ac_t ac_id)
+{
+ unsigned int tos;
+
+ tos = ac_to_tos[ac_id];
+ if (setsockopt(sockd, SOL_IP, IP_TOS, &tos, sizeof(tos)) == -1) {
+ perror("Root permission needed to set AC");
+ return (-errno);
+ }
+
+ return 0;
+}
+
+/* Deprecated */
static int fwp_vres_ac_open(fwp_ac_t ac_id)
{
int sockd;
perror("Unable to open socket for AC");
return (-errno);
}
-
- unsigned int yes = 1;
- if (setsockopt(sockd,SOL_SOCKET, SO_BROADCAST/*SO_REUSEADDR*/, &yes,
- sizeof(yes)) == -1) {
- perror("Unable to set options for socket");
- close(sockd);
- return (-errno);
- }
tos = ac_to_tos[ac_id];
* state - restart thread, set vres_resched flag
*/
pthread_cancel(vres->tx_thread);
- close(vres->ac_sockd);
/* or set vres_resched flag and return */
} else{
/* initialize msg queue */
fwp_msgq_init(&vres->tx_queue);
}
- /* open ac socket */
- if ((rv = fwp_vres_ac_open(vres->params.ac_id)) < 0) {
+ if ((rv = fwp_vres_set_ac(vres->ac_sockd, vres->params.ac_id)) < 0) {
goto err;
}
- vres->ac_sockd = rv;
pthread_attr_init(&vres->tx_thread_attr);
if ((rv = pthread_create(&vres->tx_thread, &vres->tx_thread_attr,
memcpy(&vres->params, params, sizeof(struct fwp_vres_params));
/* initialize msg queue */
fwp_msgq_init(&vres->tx_queue);
- /* open ac socket */
- if ((rv = fwp_vres_ac_open(vres->params.ac_id)) < 0) {
- goto err;
- }
- vres->ac_sockd = rv;
-
+
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){
}
vres->status = FWP_VRES_UNBOUND;
-/* return vres->params.id; */
*vresdp = vres;
return 0;
err:
return -EPERM;
vres->status = FWP_VRES_INACTIVE;
-
- /* unbind endpoint */
- fwp_send_endpoint_unbind(vres->epointd);
-
pthread_cancel(vres->tx_thread);
- close(vres->ac_sockd);
FWP_DEBUG("Vres vparam_id=%d destroyed.\n", vres->params.id);
return 0;
struct fwp_msgq *msgq = &vres->tx_queue;
struct fwp_msgb *msgb = NULL;
unsigned int ac_id = vres->params.ac_id;
- unsigned int ac_sockd = vres->ac_sockd;
+ /*unsigned int ac_sockd = vres->ac_sockd;*/
int budget = vres->params.budget;
int curr_budget;
int rc;
clock_gettime(CLOCK_MONOTONIC, &start_period);
/*msgb = fwp_msgq_dequeue(msgq);
- if (msgb){*/
+ *if (msgb){*/
curr_budget = 0;
while ((curr_budget < budget)&&
(msgb = fwp_msgq_dequeue(msgq))) {
{
fwp_vres_t *vres = vresd;
- /* test flags to check whether to send reliably*/
- if (vres->status != FWP_VRES_INACTIVE) {
+ if (vres->status == FWP_VRES_BOUND) {
return fwp_msgq_enqueue(&vres->tx_queue, msgb);
} else
return -EPERM;
}
-int _fwp_vres_bind(fwp_vres_d_t vresd, fwp_endpoint_d_t epointd, int sockd)
+int _fwp_vres_bind(fwp_vres_d_t vresd, fwp_endpoint_t *epoint)
{
fwp_vres_t *vres = vresd;
- fwp_endpoint_t *epoint = epointd;
int rv = 0;
pthread_mutex_lock(&fwp_vres_table.lock);
if (vres->status == FWP_VRES_BOUND) /*if other endpoint is assigned to vres*/
rv = -EPERM;
else {
- vres->epointd = epointd;
- /*TODO*/
- vres->ac_sockd = sockd;
+ vres->epoint = epoint;
+ vres->ac_sockd = epoint->sockd;
+ fwp_vres_set_ac(vres->ac_sockd,vres->params.ac_id);
vres->status = FWP_VRES_BOUND;
}
pthread_mutex_unlock(&fwp_vres_table.lock);