summaryrefslogtreecommitdiff
path: root/accel-pppd
diff options
context:
space:
mode:
authorKozlov Dmitry <dima@server>2011-06-22 11:31:11 +0400
committerKozlov Dmitry <dima@server>2011-06-22 11:31:11 +0400
commit83331b4d39f5fce3e274cd5e4fb1d1a57f47198a (patch)
treebdf4114b9095e306dcdc6d939fd608ba0ac6bc10 /accel-pppd
parent05ad71a30740f1cca95e9f47a8a56c65b03402ed (diff)
downloadaccel-ppp-83331b4d39f5fce3e274cd5e4fb1d1a57f47198a.tar.gz
accel-ppp-83331b4d39f5fce3e274cd5e4fb1d1a57f47198a.zip
shaper_tbf: do explicit locking over nl_socket_alloc/nl_socket_free due to this functions are not thread-safe
Diffstat (limited to 'accel-pppd')
-rw-r--r--accel-pppd/extra/shaper_tbf.c39
1 files changed, 29 insertions, 10 deletions
diff --git a/accel-pppd/extra/shaper_tbf.c b/accel-pppd/extra/shaper_tbf.c
index 997b0e9..6060027 100644
--- a/accel-pppd/extra/shaper_tbf.c
+++ b/accel-pppd/extra/shaper_tbf.c
@@ -48,6 +48,7 @@ static int temp_up_speed;
static pthread_rwlock_t shaper_lock = PTHREAD_RWLOCK_INITIALIZER;
static LIST_HEAD(shaper_list);
+static pthread_mutex_t nl_lock = PTHREAD_MUTEX_INITIALIZER;
static double tick_in_usec = 1;
static double clock_factor = 1;
@@ -384,11 +385,14 @@ static int install_shaper(const char *ifname, int down_speed, int down_burst, in
strcpy(ifr.ifr_name, ifname);
if (ioctl(sock_fd, SIOCGIFINDEX, &ifr)) {
- log_ppp_error("tbf: ioctl(SIOCGIFINDEX)", strerror(errno));
+ log_ppp_error("tbf: ioctl(SIOCGIFINDEX): %s\n", strerror(errno));
return -1;
}
+ pthread_mutex_lock(&nl_lock);
h = nl_socket_alloc();
+ pthread_mutex_unlock(&nl_lock);
+
if (!h) {
log_ppp_error("tbf: nl_socket_alloc failed\n");
return -1;
@@ -396,7 +400,7 @@ static int install_shaper(const char *ifname, int down_speed, int down_burst, in
err = nl_connect(h, NETLINK_ROUTE);
if (err < 0) {
- log_ppp_error("tbf: nl_connect: %s", strerror(errno));
+ log_ppp_error("tbf: nl_connect: %s\n", strerror(errno));
goto out;
}
@@ -413,7 +417,10 @@ static int install_shaper(const char *ifname, int down_speed, int down_burst, in
nl_close(h);
out:
+
+ pthread_mutex_lock(&nl_lock);
nl_socket_free(h);
+ pthread_mutex_unlock(&nl_lock);
return 0;
}
@@ -463,7 +470,7 @@ static int remove_shaper(const char *ifname)
strcpy(ifr.ifr_name, ifname);
if (ioctl(sock_fd, SIOCGIFINDEX, &ifr)) {
- log_ppp_error("tbf: ioctl(SIOCGIFINDEX)", strerror(errno));
+ log_ppp_error("tbf: ioctl(SIOCGIFINDEX): %s\n", strerror(errno));
return -1;
}
@@ -481,7 +488,10 @@ static int remove_shaper(const char *ifname)
.tcm_parent = TC_H_INGRESS,
};
+ pthread_mutex_lock(&nl_lock);
h = nl_socket_alloc();
+ pthread_mutex_unlock(&nl_lock);
+
if (!h) {
log_ppp_error("tbf: nl_socket_alloc failed\n");
return -1;
@@ -489,9 +499,8 @@ static int remove_shaper(const char *ifname)
err = nl_connect(h, NETLINK_ROUTE);
if (err < 0) {
- log_ppp_error("tbf: nl_connect: %s", strerror(errno));
- nl_socket_free(h);
- return -1;
+ log_ppp_error("tbf: nl_connect: %s\n", strerror(errno));
+ goto out_err1;
}
pmsg = nlmsg_alloc_simple(RTM_DELQDISC, NLM_F_CREATE | NLM_F_REPLACE);
@@ -525,17 +534,25 @@ static int remove_shaper(const char *ifname)
nlmsg_free(pmsg);
nl_close(h);
+
+ pthread_mutex_lock(&nl_lock);
nl_socket_free(h);
+ pthread_mutex_unlock(&nl_lock);
+
return 0;
out_err:
- log_ppp_error("tbf: failed to remove shaper\n");
-
if (pmsg)
nlmsg_free(pmsg);
nl_close(h);
+
+out_err1:
+ pthread_mutex_lock(&nl_lock);
nl_socket_free(h);
+ pthread_mutex_unlock(&nl_lock);
+
+ log_ppp_error("tbf: failed to remove shaper\n");
return -1;
}
@@ -978,6 +995,9 @@ static void update_shaper_tr(struct shaper_pd_t *pd)
{
struct time_range_pd_t *tr;
+ if (pd->ppp->terminating)
+ return;
+
list_for_each_entry(tr, &pd->tr_list, entry) {
if (tr->id != time_range_id)
continue;
@@ -1003,8 +1023,7 @@ static void update_shaper_tr(struct shaper_pd_t *pd)
}
} else
if (conf_verbose)
- log_ppp_info2("tbf: removed shaper\n");
-
+ log_ppp_info2("tbf: removed shaper\n");
}
static void time_range_begin_timer(struct triton_timer_t *t)