From 81660681263b7e82c60401e940926e8538c76014 Mon Sep 17 00:00:00 2001 From: "Fabio M. Di Nitto" Date: Mon, 1 Dec 2014 14:45:08 +0100 Subject: [PATCH] [PMTUd] add support for pmtud_get for who doesn't want notifications Signed-off-by: Fabio M. Di Nitto --- libknet/handle.c | 27 +++++++++++++++++++++++++++ libknet/libknet.h | 18 ++++++++++++++++++ libknet/ping_test.c | 8 ++++++++ 3 files changed, 53 insertions(+) diff --git a/libknet/handle.c b/libknet/handle.c index 4856274..2feb6d4 100644 --- a/libknet/handle.c +++ b/libknet/handle.c @@ -792,6 +792,33 @@ int knet_handle_enable_pmtud_notify(knet_handle_t knet_h, return 0; } +int knet_handle_pmtud_get(knet_handle_t knet_h, + unsigned int *link_mtu, + unsigned int *data_mtu) +{ + int savederrno = 0; + + if (!knet_h) { + errno = EINVAL; + return -1; + } + + savederrno = pthread_rwlock_rdlock(&knet_h->list_rwlock); + if (savederrno) { + log_err(knet_h, KNET_SUB_HANDLE, "Unable to get write lock: %s", + strerror(savederrno)); + errno = savederrno; + return -1; + } + + *link_mtu = knet_h->link_mtu; + *data_mtu = knet_h->data_mtu; + + pthread_rwlock_unlock(&knet_h->list_rwlock); + + return 0; +} + int knet_handle_crypto(knet_handle_t knet_h, struct knet_handle_crypto_cfg *knet_handle_crypto_cfg) { int savederrno = 0; diff --git a/libknet/libknet.h b/libknet/libknet.h index 6a47914..f6fd0b1 100644 --- a/libknet/libknet.h +++ b/libknet/libknet.h @@ -210,6 +210,24 @@ int knet_handle_enable_pmtud_notify(knet_handle_t knet_h, unsigned int link_mtu, unsigned int data_mtu)); +/* + * knet_handle_pmtud_get + * + * knet_h - pointer to knet_handle_t + * + * link_mtu - pointer where to store link_mtu + * data_mtu - pointer where to store data_mtu (see above) + * + * knet_handle_pmtud_get returns: + * + * 0 on success + * -1 on error and errno is set. + */ + +int knet_handle_pmtud_get(knet_handle_t knet_h, + unsigned int *link_mtu, + unsigned int *data_mtu); + /* * knet_handle_crypto * diff --git a/libknet/ping_test.c b/libknet/ping_test.c index 3d9d780..3a77a13 100644 --- a/libknet/ping_test.c +++ b/libknet/ping_test.c @@ -282,6 +282,7 @@ int main(int argc, char *argv[]) size_t host_ids_entries = 0; //int has_crypto = 0; int logfd; + unsigned int link_mtu = 0, data_mtu = 0; if (argc < 3) { print_usage(argv[0]); @@ -319,6 +320,13 @@ int main(int argc, char *argv[]) exit(EXIT_FAILURE); } + if (knet_handle_pmtud_get(knet_h, &link_mtu, &data_mtu)) { + printf("Unable to get PMTUd current values\n"); + exit(EXIT_FAILURE); + } else { + printf("Current PMTUd: link %u data %u\n", link_mtu, data_mtu); + } + if (knet_handle_enable_pmtud_notify(knet_h, pmtud_notify)) { printf("Unable to install PMTUd notification callback\n"); exit(EXIT_FAILURE); -- 2.39.5