~ubuntu-branches/ubuntu/jaunty/xorp/jaunty

« back to all changes in this revision

Viewing changes to fea/data_plane/control_socket/netlink_socket_utilities.cc

  • Committer: Bazaar Package Importer
  • Author(s): Jose Calhariz, Javier Fernandez-Sanguino, Jose Calhariz
  • Date: 2008-01-23 01:24:37 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20080123012437-7l2u9r0k8e7op8st
Tags: 1.5~cvs.20080128-1
[ Javier Fernandez-Sanguino ]
* Update to latest CVS contents
* Modify debian/rules to prevent autobuilders from building 
  the binary-independent components: (Closes: #441121)
  - Create a new Build-Depends-Indep with all the TeX
  components used to build documentation
  - Since autobuilders call build, which in turns calls build-indep, hack
    the debian rules file so that the documentation is only built if ps2pdf,
    dvips and pslatex are available. 
* Modify the init.d script:
  - restart action: Do not attempt to stop xorp if not running
  - stop function: fix errors in the script
  - add a try-restart action
  - restructure the init.d script, move the restart code to a function
  - review the use of echo calls and exit values
* Use, as examples, the new boot files at rtrmgr/config/

[ Jose Calhariz ]
* Add depends on ncurses-dev, I don't know why xorp use tigetstr
  function from curses.  This way the depends field change less between
  build environments.
* Removed pushd and popd commands from Makefile and replaced with cd
  commands, was a bashism and FTBFS (closes: #453637)
* debian/control converted to utf-8 (closes: #454026) (closes: #453485)
* init.d/xorp now returns 0 if disabled.
* Added Vcs-Browser and Vcs-Svn fields pointing to the repository of the
  package.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
// -*- c-basic-offset: 4; tab-width: 8; indent-tabs-mode: t -*-
2
2
 
3
 
// Copyright (c) 2001-2007 International Computer Science Institute
 
3
// Copyright (c) 2001-2008 International Computer Science Institute
4
4
//
5
5
// Permission is hereby granted, free of charge, to any person obtaining a
6
6
// copy of this software and associated documentation files (the "Software")
12
12
// notice is a summary of the XORP LICENSE file; the license in that file is
13
13
// legally binding.
14
14
 
15
 
#ident "$XORP: xorp/fea/data_plane/control_socket/netlink_socket_utilities.cc,v 1.4 2007/05/08 00:49:02 pavlin Exp $"
 
15
#ident "$XORP: xorp/fea/data_plane/control_socket/netlink_socket_utilities.cc,v 1.12 2008/01/08 23:30:09 pavlin Exp $"
16
16
 
17
17
#include "fea/fea_module.h"
18
18
 
161
161
    }
162
162
}
163
163
 
164
 
bool
 
164
int
165
165
NlmUtils::nlm_get_to_fte_cfg(const IfTree& iftree, FteX& fte,
166
166
                             const struct nlmsghdr* nlh,
167
167
                             const struct rtmsg* rtmsg, int rta_len)
171
171
    int if_index = 0;           // XXX: initialized with an invalid value
172
172
    bool lookup_ifindex = true;
173
173
    string if_name;
 
174
    string vif_name;
174
175
    int family = fte.nexthop().af();
175
176
    bool is_deleted = false;
176
177
    
184
185
    IPvX nexthop_addr(family);
185
186
    IPvX dst_addr(family);
186
187
    int dst_mask_len = 0;
187
 
    
188
 
    // rtmsg check
189
 
    if (rtmsg->rtm_type == RTN_LOCAL) {
 
188
 
 
189
    //
 
190
    // Type-specific processing
 
191
    //
 
192
    switch (rtmsg->rtm_type) {
 
193
    case RTN_LOCAL:
190
194
        // TODO: XXX: PAVPAVPAV: handle it, if needed!
191
 
        return false;           // TODO: is it really an error?
192
 
    }
193
 
 
194
 
    //
195
 
    // Try to map discard routes back to the first software discard
196
 
    // interface in the tree.
197
 
    //
198
 
    if ((rtmsg->rtm_type == RTN_BLACKHOLE) ||
199
 
        (rtmsg->rtm_type == RTN_PROHIBIT)) {
200
 
        //
201
 
        // Find first discard interface in the FEA. If we don't have one,
202
 
        // log a warning and ignore this route. Because IfTree elements
203
 
        // are held in a map, and we don't key on this property, we
204
 
        // have to walk for it.
205
 
        //
206
 
        const IfTreeInterface* pi = NULL;
207
 
        for (IfTree::IfMap::const_iterator ii = iftree.interfaces().begin();
208
 
             ii != iftree.interfaces().end(); ++ii) {
209
 
                if (ii->second.discard()) {
210
 
                        pi = &ii->second;
211
 
                        break;
212
 
                }
213
 
        }
214
 
 
215
 
        if (pi == NULL) {
216
 
            XLOG_ERROR(
217
 
"Cannot map a discard route back to an FEA soft discard interface.");
218
 
            return false;
219
 
        }
220
 
 
221
 
        if_name = pi->ifname();         // XXX: ifname == vifname
222
 
        // XXX: Do we need to change nexthop_addr?
223
 
        lookup_ifindex = false;
224
 
    }
225
 
 
226
 
    if (rtmsg->rtm_type == RTN_UNREACHABLE) {
227
 
        // Ignore "destination unreachable" notifications.
228
 
        return false;
229
 
    }
230
 
    if (rtmsg->rtm_type != RTN_UNICAST) {
 
195
        return (XORP_ERROR);            // TODO: is it really an error?
 
196
 
 
197
    case RTN_BLACKHOLE:
 
198
    case RTN_PROHIBIT:
 
199
    {
 
200
        //
 
201
        // Try to map discard routes back to the first software discard
 
202
        // interface in the tree. If we don't have one, then ignore this route.
 
203
        // We have to scan all interfaces because IfTree elements
 
204
        // are held in a map, and we don't key on this property.
 
205
        //
 
206
        const IfTreeInterface* pi = NULL;
 
207
        for (IfTree::IfMap::const_iterator ii = iftree.interfaces().begin();
 
208
             ii != iftree.interfaces().end(); ++ii) {
 
209
            if (ii->second.discard()) {
 
210
                pi = &ii->second;
 
211
                break;
 
212
            }
 
213
        }
 
214
        if (pi == NULL) {
 
215
            //
 
216
            // XXX: Cannot map a discard route back to an FEA soft discard
 
217
            // interface.
 
218
            //
 
219
            return (XORP_ERROR);
 
220
        }
 
221
        if_name = pi->ifname();
 
222
        vif_name = if_name;             // XXX: ifname == vifname
 
223
        // XXX: Do we need to change nexthop_addr?
 
224
        lookup_ifindex = false;
 
225
        break;
 
226
    }
 
227
 
 
228
    case RTN_UNREACHABLE:
 
229
    {
 
230
        //
 
231
        // Try to map unreachable routes back to the first software unreachable
 
232
        // interface in the tree. If we don't have one, then ignore this route.
 
233
        // We have to scan all interfaces because IfTree elements
 
234
        // are held in a map, and we don't key on this property.
 
235
        //
 
236
        const IfTreeInterface* pi = NULL;
 
237
        for (IfTree::IfMap::const_iterator ii = iftree.interfaces().begin();
 
238
             ii != iftree.interfaces().end(); ++ii) {
 
239
            if (ii->second.unreachable()) {
 
240
                pi = &ii->second;
 
241
                break;
 
242
            }
 
243
        }
 
244
        if (pi == NULL) {
 
245
            //
 
246
            // XXX: Cannot map an unreachable route back to an FEA soft
 
247
            // unreachable interface.
 
248
            //
 
249
            return (XORP_ERROR);
 
250
        }
 
251
        if_name = pi->ifname();
 
252
        vif_name = if_name;             // XXX: ifname == vifname
 
253
        // XXX: Do we need to change nexthop_addr?
 
254
        lookup_ifindex = false;
 
255
        break;
 
256
    }
 
257
 
 
258
    case RTN_UNICAST:
 
259
        break;
 
260
 
 
261
    default:
231
262
        XLOG_ERROR("nlm_get_to_fte_cfg() failed: "
232
 
                   "wrong AF_NETLINK route type: %d instead of %d",
233
 
                   rtmsg->rtm_type, RTN_UNICAST);
234
 
        return false;
 
263
                   "unrecognized AF_NETLINK route type: %d",
 
264
                   rtmsg->rtm_type);
 
265
        return (XORP_ERROR);
235
266
    }
 
267
 
 
268
    //
 
269
    // Check the address family
 
270
    //
236
271
    if (rtmsg->rtm_family != family)
237
 
        return false;           // Invalid address family
238
 
    
239
 
    // The attributes
 
272
        return (XORP_ERROR);            // Invalid address family
 
273
 
 
274
    //
 
275
    // Get the attributes
 
276
    //
240
277
    memset(rta_array, 0, sizeof(rta_array));
241
278
    rtattr = RTM_RTA(const_cast<struct rtmsg *>(rtmsg));
242
279
    NlmUtils::get_rtattr(rtattr, rta_len, rta_array,
254
291
        if (! dst_addr.is_unicast()) {
255
292
            // TODO: should we make this check?
256
293
            fte.zero();
257
 
            return false;       // XXX: invalid unicast address
 
294
            return (XORP_ERROR);        // XXX: invalid unicast address
258
295
        }
259
296
    }
260
297
    
278
315
        xorp_route = true;
279
316
 
280
317
    //
281
 
    // Get the interface name and index
 
318
    // Get the interface/vif name and index
282
319
    //
283
320
    if (lookup_ifindex) {
284
 
        const char* name = NULL;
285
 
 
286
321
        // Get the interface index
287
322
        if (rta_array[RTA_OIF] != NULL) {
288
323
            const uint8_t* p = static_cast<const uint8_t *>(
290
325
            if_index = extract_host_int(p);
291
326
        } else {
292
327
            XLOG_ERROR("nlm_get_to_fte_cfg() failed: no interface found");
293
 
            return false;
 
328
            return (XORP_ERROR);
294
329
        }
295
330
 
296
 
        // Get the interface name
297
 
#ifdef HAVE_IF_INDEXTONAME
298
 
        char name_buf[IF_NAMESIZE];
299
 
        name = if_indextoname(if_index, name_buf);
300
 
#endif
301
 
        if (name == NULL) {
302
 
            XLOG_FATAL("Could not find interface corresponding to index %d",
303
 
                       if_index);
 
331
        // Get the interface/vif name
 
332
        const IfTreeVif* vifp = iftree.find_vif(if_index);
 
333
        if (vifp == NULL) {
 
334
            if (! is_deleted) {
 
335
                XLOG_FATAL("Could not find interface and vif for index %d",
 
336
                           if_index);
 
337
            }
304
338
        }
305
 
        if_name = string(name);
 
339
        if_name = vifp->ifname();
 
340
        vif_name = vifp->vifname();
306
341
    }
307
342
 
308
343
    //
319
354
    //
320
355
    // TODO: define default admin distance instead of 0xffff
321
356
    //
322
 
    fte = FteX(IPvXNet(dst_addr, dst_mask_len), nexthop_addr, if_name, if_name,
323
 
               route_metric, 0xffff, xorp_route);
 
357
    fte = FteX(IPvXNet(dst_addr, dst_mask_len), nexthop_addr,
 
358
               if_name, vif_name, route_metric, 0xffff, xorp_route);
324
359
    if (is_deleted)
325
360
        fte.mark_deleted();
326
361
    
327
 
    return true;
 
362
    return (XORP_OK);
328
363
}
329
364
 
330
365
/**