Skip to content

Commit f92a5be

Browse files
Alexander Aringteigland
authored andcommitted
dlm: handle port as __be16 network byte order
This patch handles the DLM listen port setting internally as byte order as it is a value that is used as network byte on the wire. The user space still sets this value as host byte order for configfs as we don't break UAPI here. Signed-off-by: Alexander Aring <aahringo@redhat.com> Signed-off-by: David Teigland <teigland@redhat.com>
1 parent 7138c79 commit f92a5be

File tree

3 files changed

+46
-19
lines changed

3 files changed

+46
-19
lines changed

fs/dlm/config.c

Lines changed: 41 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ const struct rhashtable_params dlm_rhash_rsb_params = {
7373

7474
struct dlm_cluster {
7575
struct config_group group;
76-
unsigned int cl_tcp_port;
76+
__be16 cl_tcp_port;
7777
unsigned int cl_buffer_size;
7878
unsigned int cl_rsbtbl_size;
7979
unsigned int cl_recover_timer;
@@ -132,6 +132,45 @@ static ssize_t cluster_cluster_name_store(struct config_item *item,
132132

133133
CONFIGFS_ATTR(cluster_, cluster_name);
134134

135+
static ssize_t cluster_tcp_port_show(struct config_item *item, char *buf)
136+
{
137+
return sprintf(buf, "%u\n", be16_to_cpu(dlm_config.ci_tcp_port));
138+
}
139+
140+
static int dlm_check_zero_and_dlm_running(unsigned int x)
141+
{
142+
if (!x)
143+
return -EINVAL;
144+
145+
if (dlm_lowcomms_is_running())
146+
return -EBUSY;
147+
148+
return 0;
149+
}
150+
151+
static ssize_t cluster_tcp_port_store(struct config_item *item,
152+
const char *buf, size_t len)
153+
{
154+
int rc;
155+
u16 x;
156+
157+
if (!capable(CAP_SYS_ADMIN))
158+
return -EPERM;
159+
160+
rc = kstrtou16(buf, 0, &x);
161+
if (rc)
162+
return rc;
163+
164+
rc = dlm_check_zero_and_dlm_running(x);
165+
if (rc)
166+
return rc;
167+
168+
dlm_config.ci_tcp_port = cpu_to_be16(x);
169+
return len;
170+
}
171+
172+
CONFIGFS_ATTR(cluster_, tcp_port);
173+
135174
static ssize_t cluster_set(struct dlm_cluster *cl, unsigned int *cl_field,
136175
int *info_field, int (*check_cb)(unsigned int x),
137176
const char *buf, size_t len)
@@ -191,17 +230,6 @@ static int dlm_check_protocol_and_dlm_running(unsigned int x)
191230
return 0;
192231
}
193232

194-
static int dlm_check_zero_and_dlm_running(unsigned int x)
195-
{
196-
if (!x)
197-
return -EINVAL;
198-
199-
if (dlm_lowcomms_is_running())
200-
return -EBUSY;
201-
202-
return 0;
203-
}
204-
205233
static int dlm_check_zero(unsigned int x)
206234
{
207235
if (!x)
@@ -218,7 +246,6 @@ static int dlm_check_buffer_size(unsigned int x)
218246
return 0;
219247
}
220248

221-
CLUSTER_ATTR(tcp_port, dlm_check_zero_and_dlm_running);
222249
CLUSTER_ATTR(buffer_size, dlm_check_buffer_size);
223250
CLUSTER_ATTR(rsbtbl_size, dlm_check_zero);
224251
CLUSTER_ATTR(recover_timer, dlm_check_zero);
@@ -982,7 +1009,7 @@ int dlm_our_addr(struct sockaddr_storage *addr, int num)
9821009
#define DEFAULT_CLUSTER_NAME ""
9831010

9841011
struct dlm_config_info dlm_config = {
985-
.ci_tcp_port = DEFAULT_TCP_PORT,
1012+
.ci_tcp_port = cpu_to_be16(DEFAULT_TCP_PORT),
9861013
.ci_buffer_size = DLM_MAX_SOCKET_BUFSIZE,
9871014
.ci_rsbtbl_size = DEFAULT_RSBTBL_SIZE,
9881015
.ci_recover_timer = DEFAULT_RECOVER_TIMER,

fs/dlm/config.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ extern const struct rhashtable_params dlm_rhash_rsb_params;
2929
#define DLM_PROTO_SCTP 1
3030

3131
struct dlm_config_info {
32-
int ci_tcp_port;
32+
__be16 ci_tcp_port;
3333
int ci_buffer_size;
3434
int ci_rsbtbl_size;
3535
int ci_recover_timer;

fs/dlm/lowcomms.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -660,18 +660,18 @@ static void add_sock(struct socket *sock, struct connection *con)
660660

661661
/* Add the port number to an IPv6 or 4 sockaddr and return the address
662662
length */
663-
static void make_sockaddr(struct sockaddr_storage *saddr, uint16_t port,
663+
static void make_sockaddr(struct sockaddr_storage *saddr, __be16 port,
664664
int *addr_len)
665665
{
666666
saddr->ss_family = dlm_local_addr[0].ss_family;
667667
if (saddr->ss_family == AF_INET) {
668668
struct sockaddr_in *in4_addr = (struct sockaddr_in *)saddr;
669-
in4_addr->sin_port = cpu_to_be16(port);
669+
in4_addr->sin_port = port;
670670
*addr_len = sizeof(struct sockaddr_in);
671671
memset(&in4_addr->sin_zero, 0, sizeof(in4_addr->sin_zero));
672672
} else {
673673
struct sockaddr_in6 *in6_addr = (struct sockaddr_in6 *)saddr;
674-
in6_addr->sin6_port = cpu_to_be16(port);
674+
in6_addr->sin6_port = port;
675675
*addr_len = sizeof(struct sockaddr_in6);
676676
}
677677
memset((char *)saddr + *addr_len, 0, sizeof(struct sockaddr_storage) - *addr_len);
@@ -1121,7 +1121,7 @@ static void writequeue_entry_complete(struct writequeue_entry *e, int completed)
11211121
/*
11221122
* sctp_bind_addrs - bind a SCTP socket to all our addresses
11231123
*/
1124-
static int sctp_bind_addrs(struct socket *sock, uint16_t port)
1124+
static int sctp_bind_addrs(struct socket *sock, __be16 port)
11251125
{
11261126
struct sockaddr_storage localaddr;
11271127
struct sockaddr *addr = (struct sockaddr *)&localaddr;

0 commit comments

Comments
 (0)