~ubuntu-branches/ubuntu/raring/iproute/raring-proposed

« back to all changes in this revision

Viewing changes to ip/xfrm_policy.c

  • Committer: Bazaar Package Importer
  • Author(s): Fabio M. Di Nitto
  • Date: 2006-11-14 15:18:53 UTC
  • mto: (3.1.1 etch) (1.1.7 upstream) (23.1.1 sid)
  • mto: This revision was merged to the branch mainline in revision 11.
  • Revision ID: james.westby@ubuntu.com-20061114151853-4pojonfwjxhzx7z9
Tags: upstream-20061002
ImportĀ upstreamĀ versionĀ 20061002

Show diffs side-by-side

added added

removed removed

Lines of Context:
335
335
int xfrm_policy_print(const struct sockaddr_nl *who, struct nlmsghdr *n,
336
336
                      void *arg)
337
337
{
338
 
        FILE *fp = (FILE*)arg;
339
 
        struct xfrm_userpolicy_info *xpinfo;
340
 
        struct xfrm_user_polexpire *xpexp;
341
 
        int len = n->nlmsg_len;
342
338
        struct rtattr * tb[XFRMA_MAX+1];
343
339
        struct rtattr * rta;
 
340
        struct xfrm_userpolicy_info *xpinfo = NULL;
 
341
        struct xfrm_user_polexpire *xpexp = NULL;
 
342
        struct xfrm_userpolicy_id *xpid = NULL;
 
343
        FILE *fp = (FILE*)arg;
 
344
        int len = n->nlmsg_len;
344
345
 
345
346
        if (n->nlmsg_type != XFRM_MSG_NEWPOLICY &&
346
347
            n->nlmsg_type != XFRM_MSG_DELPOLICY &&
 
348
            n->nlmsg_type != XFRM_MSG_UPDPOLICY &&
347
349
            n->nlmsg_type != XFRM_MSG_POLEXPIRE) {
348
350
                fprintf(stderr, "Not a policy: %08x %08x %08x\n",
349
351
                        n->nlmsg_len, n->nlmsg_type, n->nlmsg_flags);
350
352
                return 0;
351
353
        }
352
354
 
353
 
        if (n->nlmsg_type == XFRM_MSG_POLEXPIRE) {
 
355
        if (n->nlmsg_type == XFRM_MSG_DELPOLICY)  {
 
356
                xpid = NLMSG_DATA(n);
 
357
                len -= NLMSG_SPACE(sizeof(*xpid));
 
358
        } else if (n->nlmsg_type == XFRM_MSG_POLEXPIRE) {
354
359
                xpexp = NLMSG_DATA(n);
355
360
                xpinfo = &xpexp->pol;
356
 
 
357
 
                len -= NLMSG_LENGTH(sizeof(*xpexp));
 
361
                len -= NLMSG_SPACE(sizeof(*xpexp));
358
362
        } else {
359
363
                xpexp = NULL;
360
364
                xpinfo = NLMSG_DATA(n);
361
 
 
362
 
                len -= NLMSG_LENGTH(sizeof(*xpinfo));
 
365
                len -= NLMSG_SPACE(sizeof(*xpinfo));
363
366
        }
364
367
 
365
368
        if (len < 0) {
367
370
                return -1;
368
371
        }
369
372
 
370
 
        if (!xfrm_policy_filter_match(xpinfo))
 
373
        if (xpinfo && !xfrm_policy_filter_match(xpinfo))
371
374
                return 0;
372
375
 
373
 
        if (n->nlmsg_type == XFRM_MSG_POLEXPIRE)
 
376
        if (n->nlmsg_type == XFRM_MSG_DELPOLICY)
 
377
                fprintf(fp, "Deleted ");
 
378
        else if (n->nlmsg_type == XFRM_MSG_UPDPOLICY)
 
379
                fprintf(fp, "Updated ");
 
380
        else if (n->nlmsg_type == XFRM_MSG_POLEXPIRE)
 
381
                fprintf(fp, "Expired ");
 
382
 
 
383
        if (n->nlmsg_type == XFRM_MSG_DELPOLICY)
 
384
                rta = XFRMPID_RTA(xpid);
 
385
        else if (n->nlmsg_type == XFRM_MSG_POLEXPIRE)
374
386
                rta = XFRMPEXP_RTA(xpexp);
375
387
        else
376
388
                rta = XFRMP_RTA(xpinfo);
377
389
 
378
390
        parse_rtattr(tb, XFRMA_MAX, rta, len);
379
391
 
380
 
        if (n->nlmsg_type == XFRM_MSG_DELPOLICY)
381
 
                fprintf(fp, "Deleted ");
382
 
        else if (n->nlmsg_type == XFRM_MSG_POLEXPIRE)
383
 
                fprintf(fp, "Expired ");
 
392
        if (n->nlmsg_type == XFRM_MSG_DELPOLICY) {
 
393
                //xfrm_policy_id_print();
 
394
                if (!tb[XFRMA_POLICY]) {
 
395
                        fprintf(stderr, "Buggy XFRM_MSG_DELPOLICY: no XFRMA_POLICY\n");
 
396
                        return -1;
 
397
                }
 
398
                if (RTA_PAYLOAD(tb[XFRMA_POLICY]) < sizeof(*xpinfo)) {
 
399
                        fprintf(stderr, "Buggy XFRM_MSG_DELPOLICY: too short XFRMA_POLICY len\n");
 
400
                        return -1;
 
401
                }
 
402
                xpinfo = (struct xfrm_userpolicy_info *)RTA_DATA(tb[XFRMA_POLICY]);
 
403
        }
384
404
 
385
405
        xfrm_policy_info_print(xpinfo, tb, fp, NULL, NULL);
386
406
 
392
412
 
393
413
        if (oneline)
394
414
                fprintf(fp, "\n");
 
415
        fflush(fp);
395
416
 
396
417
        return 0;
397
418
}