aboutsummaryrefslogtreecommitdiffstats
path: root/include/linux/sunrpc
diff options
context:
space:
mode:
authorChuck Lever <chuck.lever@oracle.com>2009-03-12 12:07:14 -0400
committerJ. Bruce Fields <bfields@citi.umich.edu>2009-03-18 18:13:28 -0400
commit2795e53b4ed5d1f49d2283f416c922f55ec7d461 (patch)
treecba9e5c2bcbbf7da75b4c73c7398b20a770262d2 /include/linux/sunrpc
parent0953e620de0538cbd081f1b45126f6098112a598 (diff)
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: Chuck Lever <chuck.lever@oracle.com> Signed-off-by: J. Bruce Fields <bfields@citi.umich.edu>
Diffstat (limited to 'include/linux/sunrpc')
-rw-r--r--include/linux/sunrpc/svc_xprt.h46
1 files changed, 26 insertions, 20 deletions
diff --git a/include/linux/sunrpc/svc_xprt.h b/include/linux/sunrpc/svc_xprt.h
index 0127daca4354..959b931b6053 100644
--- a/include/linux/sunrpc/svc_xprt.h
+++ b/include/linux/sunrpc/svc_xprt.h
@@ -88,29 +88,32 @@ static inline void svc_xprt_get(struct svc_xprt *xprt)
88 kref_get(&xprt->xpt_ref); 88 kref_get(&xprt->xpt_ref);
89} 89}
90static inline void svc_xprt_set_local(struct svc_xprt *xprt, 90static inline void svc_xprt_set_local(struct svc_xprt *xprt,
91 struct sockaddr *sa, int salen) 91 const struct sockaddr *sa,
92 const size_t salen)
92{ 93{
93 memcpy(&xprt->xpt_local, sa, salen); 94 memcpy(&xprt->xpt_local, sa, salen);
94 xprt->xpt_locallen = salen; 95 xprt->xpt_locallen = salen;
95} 96}
96static inline void svc_xprt_set_remote(struct svc_xprt *xprt, 97static inline void svc_xprt_set_remote(struct svc_xprt *xprt,
97 struct sockaddr *sa, int salen) 98 const struct sockaddr *sa,
99 const size_t salen)
98{ 100{
99 memcpy(&xprt->xpt_remote, sa, salen); 101 memcpy(&xprt->xpt_remote, sa, salen);
100 xprt->xpt_remotelen = salen; 102 xprt->xpt_remotelen = salen;
101} 103}
102static inline unsigned short svc_addr_port(struct sockaddr *sa) 104static inline unsigned short svc_addr_port(const struct sockaddr *sa)
103{ 105{
104 unsigned short ret = 0; 106 const struct sockaddr_in *sin = (const struct sockaddr_in *)sa;
107 const struct sockaddr_in6 *sin6 = (const struct sockaddr_in6 *)sa;
108
105 switch (sa->sa_family) { 109 switch (sa->sa_family) {
106 case AF_INET: 110 case AF_INET:
107 ret = ntohs(((struct sockaddr_in *)sa)->sin_port); 111 return ntohs(sin->sin_port);
108 break;
109 case AF_INET6: 112 case AF_INET6:
110 ret = ntohs(((struct sockaddr_in6 *)sa)->sin6_port); 113 return ntohs(sin6->sin6_port);
111 break;
112 } 114 }
113 return ret; 115
116 return 0;
114} 117}
115 118
116static inline size_t svc_addr_len(struct sockaddr *sa) 119static inline size_t svc_addr_len(struct sockaddr *sa)
@@ -124,36 +127,39 @@ static inline size_t svc_addr_len(struct sockaddr *sa)
124 return -EAFNOSUPPORT; 127 return -EAFNOSUPPORT;
125} 128}
126 129
127static inline unsigned short svc_xprt_local_port(struct svc_xprt *xprt) 130static inline unsigned short svc_xprt_local_port(const struct svc_xprt *xprt)
128{ 131{
129 return svc_addr_port((struct sockaddr *)&xprt->xpt_local); 132 return svc_addr_port((const struct sockaddr *)&xprt->xpt_local);
130} 133}
131 134
132static inline unsigned short svc_xprt_remote_port(struct svc_xprt *xprt) 135static inline unsigned short svc_xprt_remote_port(const struct svc_xprt *xprt)
133{ 136{
134 return svc_addr_port((struct sockaddr *)&xprt->xpt_remote); 137 return svc_addr_port((const struct sockaddr *)&xprt->xpt_remote);
135} 138}
136 139
137static inline char *__svc_print_addr(struct sockaddr *addr, 140static inline char *__svc_print_addr(const struct sockaddr *addr,
138 char *buf, size_t len) 141 char *buf, const size_t len)
139{ 142{
143 const struct sockaddr_in *sin = (const struct sockaddr_in *)addr;
144 const struct sockaddr_in6 *sin6 = (const struct sockaddr_in6 *)addr;
145
140 switch (addr->sa_family) { 146 switch (addr->sa_family) {
141 case AF_INET: 147 case AF_INET:
142 snprintf(buf, len, "%pI4, port=%u", 148 snprintf(buf, len, "%pI4, port=%u", &sin->sin_addr,
143 &((struct sockaddr_in *)addr)->sin_addr, 149 ntohs(sin->sin_port));
144 ntohs(((struct sockaddr_in *) addr)->sin_port));
145 break; 150 break;
146 151
147 case AF_INET6: 152 case AF_INET6:
148 snprintf(buf, len, "%pI6, port=%u", 153 snprintf(buf, len, "%pI6, port=%u",
149 &((struct sockaddr_in6 *)addr)->sin6_addr, 154 &sin6->sin6_addr,
150 ntohs(((struct sockaddr_in6 *) addr)->sin6_port)); 155 ntohs(sin6->sin6_port));
151 break; 156 break;
152 157
153 default: 158 default:
154 snprintf(buf, len, "unknown address type: %d", addr->sa_family); 159 snprintf(buf, len, "unknown address type: %d", addr->sa_family);
155 break; 160 break;
156 } 161 }
162
157 return buf; 163 return buf;
158} 164}
159#endif /* SUNRPC_SVC_XPRT_H */ 165#endif /* SUNRPC_SVC_XPRT_H */