Commit 2795e53b authored by Chuck Lever's avatar Chuck Lever Committed by J. Bruce Fields

SUNRPC: Clean up static inline functions in svc_xprt.h

Clean up:  Enable the use of const arguments in higher level svc_ APIs
by adding const to the arguments of the helper functions in svc_xprt.h
Signed-off-by: default avatarChuck Lever <chuck.lever@oracle.com>
Signed-off-by: default avatarJ. Bruce Fields <bfields@citi.umich.edu>
parent 0953e620
...@@ -88,29 +88,32 @@ static inline void svc_xprt_get(struct svc_xprt *xprt) ...@@ -88,29 +88,32 @@ static inline void svc_xprt_get(struct svc_xprt *xprt)
kref_get(&xprt->xpt_ref); kref_get(&xprt->xpt_ref);
} }
static inline void svc_xprt_set_local(struct svc_xprt *xprt, static inline void svc_xprt_set_local(struct svc_xprt *xprt,
struct sockaddr *sa, int salen) const struct sockaddr *sa,
const size_t salen)
{ {
memcpy(&xprt->xpt_local, sa, salen); memcpy(&xprt->xpt_local, sa, salen);
xprt->xpt_locallen = salen; xprt->xpt_locallen = salen;
} }
static inline void svc_xprt_set_remote(struct svc_xprt *xprt, static inline void svc_xprt_set_remote(struct svc_xprt *xprt,
struct sockaddr *sa, int salen) const struct sockaddr *sa,
const size_t salen)
{ {
memcpy(&xprt->xpt_remote, sa, salen); memcpy(&xprt->xpt_remote, sa, salen);
xprt->xpt_remotelen = salen; xprt->xpt_remotelen = salen;
} }
static inline unsigned short svc_addr_port(struct sockaddr *sa) static inline unsigned short svc_addr_port(const struct sockaddr *sa)
{ {
unsigned short ret = 0; const struct sockaddr_in *sin = (const struct sockaddr_in *)sa;
const struct sockaddr_in6 *sin6 = (const struct sockaddr_in6 *)sa;
switch (sa->sa_family) { switch (sa->sa_family) {
case AF_INET: case AF_INET:
ret = ntohs(((struct sockaddr_in *)sa)->sin_port); return ntohs(sin->sin_port);
break;
case AF_INET6: case AF_INET6:
ret = ntohs(((struct sockaddr_in6 *)sa)->sin6_port); return ntohs(sin6->sin6_port);
break;
} }
return ret;
return 0;
} }
static inline size_t svc_addr_len(struct sockaddr *sa) static inline size_t svc_addr_len(struct sockaddr *sa)
...@@ -124,36 +127,39 @@ static inline size_t svc_addr_len(struct sockaddr *sa) ...@@ -124,36 +127,39 @@ static inline size_t svc_addr_len(struct sockaddr *sa)
return -EAFNOSUPPORT; return -EAFNOSUPPORT;
} }
static inline unsigned short svc_xprt_local_port(struct svc_xprt *xprt) static inline unsigned short svc_xprt_local_port(const struct svc_xprt *xprt)
{ {
return svc_addr_port((struct sockaddr *)&xprt->xpt_local); return svc_addr_port((const struct sockaddr *)&xprt->xpt_local);
} }
static inline unsigned short svc_xprt_remote_port(struct svc_xprt *xprt) static inline unsigned short svc_xprt_remote_port(const struct svc_xprt *xprt)
{ {
return svc_addr_port((struct sockaddr *)&xprt->xpt_remote); return svc_addr_port((const struct sockaddr *)&xprt->xpt_remote);
} }
static inline char *__svc_print_addr(struct sockaddr *addr, static inline char *__svc_print_addr(const struct sockaddr *addr,
char *buf, size_t len) char *buf, const size_t len)
{ {
const struct sockaddr_in *sin = (const struct sockaddr_in *)addr;
const struct sockaddr_in6 *sin6 = (const struct sockaddr_in6 *)addr;
switch (addr->sa_family) { switch (addr->sa_family) {
case AF_INET: case AF_INET:
snprintf(buf, len, "%pI4, port=%u", snprintf(buf, len, "%pI4, port=%u", &sin->sin_addr,
&((struct sockaddr_in *)addr)->sin_addr, ntohs(sin->sin_port));
ntohs(((struct sockaddr_in *) addr)->sin_port));
break; break;
case AF_INET6: case AF_INET6:
snprintf(buf, len, "%pI6, port=%u", snprintf(buf, len, "%pI6, port=%u",
&((struct sockaddr_in6 *)addr)->sin6_addr, &sin6->sin6_addr,
ntohs(((struct sockaddr_in6 *) addr)->sin6_port)); ntohs(sin6->sin6_port));
break; break;
default: default:
snprintf(buf, len, "unknown address type: %d", addr->sa_family); snprintf(buf, len, "unknown address type: %d", addr->sa_family);
break; break;
} }
return buf; return buf;
} }
#endif /* SUNRPC_SVC_XPRT_H */ #endif /* SUNRPC_SVC_XPRT_H */
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment