Revision 48e5f32d sysdep/linux/sysio.h

View differences:

sysdep/linux/sysio.h
30 30
  ipa_ntoh(*a);
31 31
}
32 32

  
33
static inline char *
34
sysio_bind_to_iface(sock *s)
35
{
36
  struct ifreq ifr;
37
  strcpy(ifr.ifr_name, s->iface->name);
38
  if (setsockopt(s->fd, SOL_SOCKET, SO_BINDTODEVICE, &ifr, sizeof(ifr)) < 0)
39
    return "SO_BINDTODEVICE";
40

  
41
  return NULL;
42
}
43

  
44 33
#else
45 34

  
46 35
static inline void
......
69 58
#endif
70 59

  
71 60

  
72
static inline void fill_mreqn(struct ip_mreqn *m, struct iface *ifa, ip_addr saddr, ip_addr maddr)
61
static inline void fill_mreqn(struct ip_mreqn *m, ip_addr maddr, struct iface *ifa)
73 62
{
74 63
  bzero(m, sizeof(*m));
75 64
  m->imr_ifindex = ifa->index;
76
  set_inaddr(&m->imr_address, saddr);
77 65
  set_inaddr(&m->imr_multiaddr, maddr);
78 66
}
79 67

  
......
90 78
    return "IP_MULTICAST_TTL";
91 79

  
92 80
  /* This defines where should we send _outgoing_ multicasts */
93
  fill_mreqn(&m, s->iface, s->saddr, IPA_NONE);
81
  fill_mreqn(&m, IPA_NONE, s->iface);
94 82
  if (setsockopt(s->fd, SOL_IP, IP_MULTICAST_IF, &m, sizeof(m)) < 0)
95 83
    return "IP_MULTICAST_IF";
96 84

  
97
  /* Is this necessary? */
98
  struct ifreq ifr;
99
  strcpy(ifr.ifr_name, s->iface->name);
100
  if (setsockopt(s->fd, SOL_SOCKET, SO_BINDTODEVICE, &ifr, sizeof(ifr)) < 0)
101
    return "SO_BINDTODEVICE";
102

  
103 85
  return NULL;
104 86
}
105 87

  
......
109 91
  struct ip_mreqn m;
110 92

  
111 93
  /* And this one sets interface for _receiving_ multicasts from */
112
  fill_mreqn(&m, s->iface, s->saddr, maddr);
94
  fill_mreqn(&m, maddr, s->iface);
113 95
  if (setsockopt(s->fd, SOL_IP, IP_ADD_MEMBERSHIP, &m, sizeof(m)) < 0)
114 96
    return "IP_ADD_MEMBERSHIP";
115 97

  
......
122 104
  struct ip_mreqn m;
123 105

  
124 106
  /* And this one sets interface for _receiving_ multicasts from */
125
  fill_mreqn(&m, s->iface, s->saddr, maddr);
107
  fill_mreqn(&m, maddr, s->iface);
126 108
  if (setsockopt(s->fd, SOL_IP, IP_DROP_MEMBERSHIP, &m, sizeof(m)) < 0)
127 109
    return "IP_DROP_MEMBERSHIP";
128 110

  
......
132 114
#endif
133 115

  
134 116

  
135
#include <linux/socket.h>
136
#include <linux/tcp.h>
137

  
138
/* For the case that we have older kernel headers */
117
/* For the case that we have older libc headers */
139 118
/* Copied from Linux kernel file include/linux/tcp.h */
140 119

  
141 120
#ifndef TCP_MD5SIG
......
175 154
      memcpy(&md5.tcpm_key, passwd, len);
176 155
    }
177 156

  
178
  int rv = setsockopt(s->fd, IPPROTO_TCP, TCP_MD5SIG, &md5, sizeof(md5));
157
  int rv = setsockopt(s->fd, SOL_TCP, TCP_MD5SIG, &md5, sizeof(md5));
179 158

  
180 159
  if (rv < 0) 
181 160
    {
......
203 182
  int ok = 1;
204 183

  
205 184
  if ((s->flags & SKF_LADDR_RX) &&
206
      (setsockopt(s->fd, IPPROTO_IP, IP_PKTINFO, &ok, sizeof(ok)) < 0))
185
      (setsockopt(s->fd, SOL_IP, IP_PKTINFO, &ok, sizeof(ok)) < 0))
207 186
    return "IP_PKTINFO";
208 187

  
209 188
  if ((s->flags & SKF_TTL_RX) &&
210
      (setsockopt(s->fd, IPPROTO_IP, IP_RECVTTL, &ok, sizeof(ok)) < 0))
189
      (setsockopt(s->fd, SOL_IP, IP_RECVTTL, &ok, sizeof(ok)) < 0))
211 190
    return "IP_RECVTTL";
212 191

  
213 192
  return NULL;
......
222 201

  
223 202
  for (cm = CMSG_FIRSTHDR(msg); cm != NULL; cm = CMSG_NXTHDR(msg, cm))
224 203
  {
225
    if (cm->cmsg_level == IPPROTO_IP && cm->cmsg_type == IP_PKTINFO)
204
    if (cm->cmsg_level == SOL_IP && cm->cmsg_type == IP_PKTINFO)
226 205
      pi = (struct in_pktinfo *) CMSG_DATA(cm);
227 206

  
228
    if (cm->cmsg_level == IPPROTO_IP && cm->cmsg_type == IP_TTL)
207
    if (cm->cmsg_level == SOL_IP && cm->cmsg_type == IP_TTL)
229 208
      ttl = (int *) CMSG_DATA(cm);
230 209
  }
231 210

  
......
249 228
  return;
250 229
}
251 230

  
252
/*
253 231
static void
254 232
sysio_prepare_tx_cmsgs(sock *s, struct msghdr *msg, void *cbuf, size_t cbuflen)
255 233
{
256 234
  struct cmsghdr *cm;
257 235
  struct in_pktinfo *pi;
258 236

  
259
  if (!(s->flags & SKF_LADDR_TX))
260
    return;
261

  
262 237
  msg->msg_control = cbuf;
263 238
  msg->msg_controllen = cbuflen;
264 239

  
265 240
  cm = CMSG_FIRSTHDR(msg);
266
  cm->cmsg_level = IPPROTO_IP;
241
  cm->cmsg_level = SOL_IP;
267 242
  cm->cmsg_type = IP_PKTINFO;
268 243
  cm->cmsg_len = CMSG_LEN(sizeof(*pi));
269 244

  
270 245
  pi = (struct in_pktinfo *) CMSG_DATA(cm);
271
  set_inaddr(&pi->ipi_spec_dst, s->saddr);
272 246
  pi->ipi_ifindex = s->iface ? s->iface->index : 0;
247
  set_inaddr(&pi->ipi_spec_dst, s->saddr);
248
  set_inaddr(&pi->ipi_addr, IPA_NONE);
273 249

  
274 250
  msg->msg_controllen = cm->cmsg_len;
275 251
}
276
*/
252

  
277 253

  
278 254
#endif
279 255

  
......
292 268
static int
293 269
sk_set_min_ttl4(sock *s, int ttl)
294 270
{
295
  if (setsockopt(s->fd, IPPROTO_IP, IP_MINTTL, &ttl, sizeof(ttl)) < 0)
271
  if (setsockopt(s->fd, SOL_IP, IP_MINTTL, &ttl, sizeof(ttl)) < 0)
296 272
  {
297 273
    if (errno == ENOPROTOOPT)
298 274
      log(L_ERR "Kernel does not support IPv4 TTL security");
......
310 286
static int
311 287
sk_set_min_ttl6(sock *s, int ttl)
312 288
{
313
  if (setsockopt(s->fd, IPPROTO_IPV6, IPV6_MINHOPCOUNT, &ttl, sizeof(ttl)) < 0)
289
  if (setsockopt(s->fd, SOL_IPV6, IPV6_MINHOPCOUNT, &ttl, sizeof(ttl)) < 0)
314 290
  {
315 291
    if (errno == ENOPROTOOPT)
316 292
      log(L_ERR "Kernel does not support IPv6 TTL security");

Also available in: Unified diff