Statistics
| Branch: | Revision:

iof-bird-daemon / sysdep / unix / krt-set.c @ b1a1faba

History | View | Annotate | Download (2.24 KB)

1
/*
2
 *        BIRD -- Unix Routing Table Syncing
3
 *
4
 *        (c) 1998--2000 Martin Mares <mj@ucw.cz>
5
 *
6
 *        Can be freely distributed and used under the terms of the GNU GPL.
7
 */
8

    
9
#include <sys/types.h>
10
#include <sys/socket.h>
11
#include <netinet/in.h>
12
#include <sys/ioctl.h>
13
#include <net/route.h>
14

    
15
#undef LOCAL_DEBUG
16
#define LOCAL_DEBUG
17

    
18
#include "nest/bird.h"
19
#include "nest/iface.h"
20
#include "nest/route.h"
21
#include "nest/protocol.h"
22
#include "lib/unix.h"
23
#include "lib/krt.h"
24
#include "lib/string.h"
25

    
26
int
27
krt_capable(rte *e)
28
{
29
  rta *a = e->attrs;
30

    
31
#ifdef CONFIG_AUTO_ROUTES
32
  if (a->source == RTS_DEVICE)
33
    return 0;
34
#endif
35
  return
36
    a->cast == RTC_UNICAST &&
37
    (a->dest == RTD_ROUTER
38
     || a->dest == RTD_DEVICE
39
#ifdef RTF_REJECT
40
     || a->dest == RTD_UNREACHABLE                /* FIXME Blackhole, prohibited?? */
41
#endif
42
     );
43
}
44

    
45
static void
46
krt_ioctl(int ioc, rte *e, char *name)
47
{
48
  net *net = e->net;
49
  struct ortentry re;
50
  rta *a = e->attrs;
51

    
52
  bzero(&re, sizeof(re));
53
  fill_in_sockaddr((struct sockaddr_in *) &re.rt_dst, net->n.prefix, 0);
54
  //fill_in_sockaddr((struct sockaddr_in *) &re.rt_genmask, ipa_mkmask(net->n.pxlen), 0);
55
  re.rt_flags = RTF_UP;
56
  if (net->n.pxlen == 32)
57
    re.rt_flags |= RTF_HOST;
58
  switch (a->dest)
59
    {
60
    case RTD_ROUTER:
61
      fill_in_sockaddr((struct sockaddr_in *) &re.rt_gateway, a->gw, 0);
62
      re.rt_flags |= RTF_GATEWAY;
63
      break;
64
    case RTD_DEVICE:
65
      //re.rt_dev = a->iface->name;
66
      break;
67
#ifdef RTF_REJECT
68
    case RTD_UNREACHABLE:
69
      re.rt_flags |= RTF_REJECT;
70
      break;
71
#endif
72
    default:
73
      bug("krt set: unknown flags, but not filtered");
74
    }
75

    
76
  if (ioctl(if_scan_sock, ioc, &re) < 0)
77
    log(L_ERR "%s(%I/%d): %m", name, net->n.prefix, net->n.pxlen);
78
}
79

    
80
void
81
krt_set_notify(struct krt_proto *p, net *net, rte *new, rte *old)
82
{
83
  if (old)
84
    {
85
      DBG("krt_remove_route(%I/%d)\n", net->n.prefix, net->n.pxlen);
86
      krt_ioctl(SIOCDELRT, old, "SIOCDELRT");
87
    }
88
  if (new)
89
    {
90
      DBG("krt_add_route(%I/%d)\n", net->n.prefix, net->n.pxlen);
91
      krt_ioctl(SIOCADDRT, new, "SIOCADDRT");
92
    }
93
}
94

    
95
void
96
krt_set_start(struct krt_proto *x, int first)
97
{
98
  if (if_scan_sock < 0)
99
    bug("krt set: missing socket");
100
}
101

    
102
void
103
krt_set_construct(struct krt_config *c)
104
{
105
}
106

    
107
void
108
krt_set_shutdown(struct krt_proto *x, int last)
109
{
110
}