📄 netconf.c
字号:
template_flags = STRTOUL(argv[8], 0, 0); metric = STRTOUL(argv[9], 0, 0); tag = STRTOUL(argv[10], 0, 0); if (!ospf_mgr_add_export_template(ospf, template_num, ospf_export_template_key, template_bits, template_flags, metric, tag)) fprintf(stderr, "Couldn't set OSPF export template\n");}void netconfig_ospf_import_filter(bits32_t *entity, int argc, char *argv[]){ struct OSPF *ospf = (struct OSPF *) *entity; bits32_t *filter; int flt_cnt; if ((argc == 0) || (argc > OSPF_MAX_TEMPLATES + 1)) { fprintf(stderr, "Bad argcount for ospf-import-filter\n"); return; } if ((filter = GLUE_ALLOC(argc * sizeof(bits32_t))) == NULL) { fprintf(stderr, "Couldn't allocate memory for filter\n"); return; } for (flt_cnt = 0; flt_cnt < argc; flt_cnt++) { filter[flt_cnt] = STRTOUL(argv[flt_cnt], 0, 0); } if (!ospf_mgr_add_import_filter(ospf, (int *)filter)) { fprintf(stderr, "Unable to add import filter!\n"); } GLUE_FREE(filter); return;}void netconfig_ospf_export_filter(bits32_t *entity, int argc, char *argv[]){ struct OSPF *ospf = (struct OSPF *) *entity; bits32_t *filter; int flt_cnt; if ((argc == 0) || (argc > OSPF_MAX_TEMPLATES + 1)) { fprintf(stderr, "Bad argcount for ospf-export-filter\n"); return; } if ((filter = GLUE_ALLOC(argc * sizeof(bits32_t))) == NULL) { fprintf(stderr, "Couldn't allocate memory for filter\n"); return; } for (flt_cnt = 0; flt_cnt < argc; flt_cnt++) { filter[flt_cnt] = STRTOUL(argv[flt_cnt], 0, 0); } if (!ospf_mgr_add_export_filter(ospf, (int *)filter)) { fprintf(stderr, "Unable to add export filter!\n"); } GLUE_FREE(filter); return;}#if 0#if OSPF_IMPORT_POLICY_KEY_LEN > OSPF_EXPORT_POLICY_KEY_LEN#define OSPF_POLICY_KEY_LEN OSPF_IMPORT_POLICY_KEY_LEN#else#define OSPF_POLICY_KEY_LEN OSPF_EXPORT_POLICY_KEY_LEN#endifstatic void netconfig_ospf_import_policy(bits32_t *entity, int argc, char *argv[]){ struct OSPF *ospf = (struct OSPF *) *entity; bits32_t ospf_import_pol_key[OSPF_IMPORT_POLICY_KEY_LEN]; bits32_t pol_bits, pref; if (argc != (OSPF_IMPORT_POLICY_KEY_LEN + 2)) { fprintf(stderr, "---OSPF Import Policy Size Mismatch---\n"); return; } MEMSET(&ospf_import_pol_key, 0, sizeof(ospf_import_pol_key)); ospf_import_pol_key[OSPF_IMPORT_POL_MASK] = STRTOUL(argv[0], 0, 0); ospf_import_pol_key[OSPF_IMPORT_POL_NET] = STRTOUL(argv[1], 0, 0); pol_bits = STRTOUL(argv[2], 0, 0); pref = STRTOUL(argv[3], 0, 0); if (!ospf_mgr_add_import_policy(ospf, ospf_import_pol_key, pol_bits, pref)) fprintf(stderr, "Couldn't set OSPF import policy\n");}static void netconfig_ospf_export_policy(bits32_t *entity, int argc, char *argv[]){ struct OSPF *ospf = (struct OSPF *) *entity; bits32_t ospf_export_pol_key[OSPF_EXPORT_POLICY_KEY_LEN]; bits32_t pol_bits, pol_flags, metric, tag; if (argc != (OSPF_EXPORT_POLICY_KEY_LEN + 4)) { fprintf(stderr, "---OSPF Export Policy Size Mismatch---\n"); return; } MEMSET(&ospf_export_pol_key, 0, sizeof(ospf_export_pol_key)); ospf_export_pol_key[OSPF_EXPORT_POL_MASK] = STRTOUL(argv[0], 0, 0); ospf_export_pol_key[OSPF_EXPORT_POL_NET] = STRTOUL(argv[1], 0, 0); ospf_export_pol_key[OSPF_EXPORT_SPECIFIC1] = STRTOUL(argv[2], 0, 0); ospf_export_pol_key[OSPF_EXPORT_SPECIFIC2] = STRTOUL(argv[3], 0, 0); ospf_export_pol_key[OSPF_EXPORT_POL_PROTO] = STRTOUL(argv[4], 0, 0); pol_bits = STRTOUL(argv[5], 0, 0); pol_flags = STRTOUL(argv[6], 0, 0); metric = STRTOUL(argv[7], 0, 0); tag = STRTOUL(argv[8], 0, 0); if (!ospf_mgr_add_export_policy(ospf, ospf_export_pol_key, pol_bits, pol_flags, metric, tag)) fprintf(stderr, "Couldn't set OSPF export policy\n");}#endif/* * This is a first cut. OSPF has so many possible configuration options * that any example that tried to use them all would be completely unreadable. */static void netconfig_ospf(void){ inaddr_t id = 0; struct OSPF *ospf; struct AREA *area, *backbone = NULL; IP_IFB *ifb; net_if *n; sbits32_t metric = -1, priority = -1, transdly = -1, retrans = -1; sbits32_t hello = -1, rtrdead = -1, auth_type = -1; bits8_t auth_key[8]; struct INTF *intf; struct OspfGeneralGroup gen_group; struct OspfAreaEntry area_entry; struct OspfIfEntry if_entry; struct OspfIfMetricEntry if_metric; struct OspfVirtIfEntry virtif_entry; struct ini_handle_saved saved_ini, saved_ini2; char *s, tag[256], tag2[256], tag3[256], tag4[256], tag5[256], tag6[256]; char *argv[20]; bits32_t range_key[2]; int argc; static policy_dispatch_t ospf_policy_dispatch[] = { { "ospf-import-template", netconfig_ospf_import_template }, { "ospf-export-template", netconfig_ospf_export_template }, { "ospf-import-filter", netconfig_ospf_import_filter }, { "ospf-export-filter", netconfig_ospf_export_filter }, { 0, 0 } }; MEMSET(&gen_group, 0, sizeof(gen_group)); /* * Specifying the router-id is optional, the code tries to guess it * if no explicit ID is provided. Look for it first, to simplify * the control structure later in this routine. */ if ((s = INI_LOOKUP(courier_section, "ospf-router-id"))) id = atoinet(s); /* * You don't have to specify Autonomous System Border Router (ASBR) status * unless this router is an ASBR (ie, it defaults to FALSE). */ if ((s = INI_LOOKUP(courier_section, "ospf-asbr-status"))) gen_group.ospfASBdrRtrStatus = atoi(s); /* * Slightly strange control structure, to let us skip OSPF configuration * entirely if there are no area entries in the configuration file. */ if (!(s = INI_ITER_START(courier_section, "ospf-area")) && !(s = INI_LOOKUP(courier_section, "ospf-stub-area")) && !(s = INI_LOOKUP(courier_section, "ospf-nssa"))) { printf(" -- No OSPF area entries in configuration file --\n"); return; } /* * If we get here, we want to bring up OSPF. * Try to create and enable the OSPF instance. */ if (!(ospf = ospf_create_instance(id))) { fprintf(stderr, "Couldn't create OSPF instance\n"); return; } gen_group.ospfRouterId = ospf->my_rtr_id; gen_group.ospfExtLsdbLimit = -1; if (!ospf_mgr_enable_gen(ospf, &gen_group, MGR_ENTITY_DISABLE, 0)) { fprintf(stderr, "Couldn't enable OSPF instance\n"); return; } /* Now using the new improved policy management scheme */ netconfig_courier_policies((bits32_t *) &ospf, ospf_policy_dispatch); for (s = INI_LOOKUP(courier_section, "ospf-area"); s; s = INI_ITER_NEXT()) { /* * Try to create the area. Minimal config for now, we'll probably * add more parameters later. */ MEMSET(&area_entry, 0, sizeof(area_entry)); if ((argc = parse_line(s, argv, sizeof(argv)/sizeof(*argv))) < 2) { fprintf(stderr, "Couldn't parse ospf-area \"%s\", ignoring\n", s); continue; } sprintf(tag, "ospf-area-%s", argv[0]); sprintf(tag3, "ospf-area-addr-%s", argv[0]); sprintf(tag4, "ospf-area-unnum-%s", argv[0]); sprintf(tag5, "ospf-area-virt-%s", argv[0]); sprintf(tag6, "ospf-net-range-%s", argv[0]); area_entry.ospfAreaId = atoinet(argv[1]); area_entry.ospfImportASExtern = OSPF_MIBimportExternal; if (!(area = ospf_mgr_create_area(ospf->ipi, ospf, &area_entry, 0))) { fprintf(stderr, "Couldn't create OSPF area %s\n", argv[0]); continue; } if (!ospf_mgr_enable_area(ospf, area, 1, MGR_ENTITY_DISABLE)) { fprintf(stderr, "Couldn't enable OSPF area %s\n", argv[0]); ospf_mgr_delete_area(ospf->ipi, area); continue; } if (area_entry.ospfAreaId == 0) backbone = area; printf(" -- OSPF Area %s %s --\n", argv[0], argv[1]); /* * Now look for interfaces that we want to add to this area. * Again, this is minimal, we may add more arguments later */ /* ospf-area-a0 = <interface> <metric> <pref> */ ini_save(ini_handle, &saved_ini); for (s = INI_ITER_START(courier_section, tag); s; s = INI_ITER_NEXT()) { if ((argc = parse_line(s, argv, sizeof(argv)/sizeof(*argv))) < 1) { fprintf(stderr, "Couldn't parse %s \"%s\", ignoring\n", tag, s); continue; } MEMSET(&if_entry, 0, sizeof(if_entry)); MEMSET(&if_metric, 0, sizeof(if_metric)); MEMSET(auth_key, 0, 8); metric = priority = transdly = retrans = hello = rtrdead = -1; auth_type = -1; switch(argc) { case 9: MEMCPY(auth_key, argv[8], strlen(argv[8])); case 8: auth_type = atoi(argv[7]); case 7: rtrdead = atoi(argv[6]); case 6: hello = atoi(argv[5]); case 5: retrans = atoi(argv[4]); case 4: transdly = atoi(argv[3]); case 3: priority = atoi(argv[2]); case 2: metric = atoi(argv[1]); default: break; } sprintf(tag2, "%s-address", argv[0]); ini_save(ini_handle, &saved_ini2); s = INI_LOOKUP(attache_section, tag2); ini_restore(ini_handle, &saved_ini2); if (!s) { fprintf(stderr, "Unable to find entry for \"%s\" in ini file\n", tag2); continue; } if (!(ifb = courier_get_ifb(atoinet(s)))) { fprintf(stderr, "Address \"%s\" has no IFB\n", s); continue; } if (!(intf = ospf_mgr_create_intf(ospf, ifb, area, ifb->ifb_type, 0, 0, 0))) { fprintf(stderr, "Couldn't create OSPF INTF for \"%s\"\n", s); continue; } /* And now we'll try to set some parameters for this interface */ if (ospf_mgr_get_intf_entry(ospf, (void *)intf, GET_THIS, &if_entry, 0) || ospf_mgr_get_if_metric(ospf, (void *)intf, GET_THIS, &if_metric, 0)) continue; if (metric >= 0) if_metric.ospfIfMetricCost = metric; if (priority >= 0) if_entry.ospfIfRtrPriority = priority; if (transdly >= 0) if_entry.ospfIfTransitDelay = transdly; if (retrans >= 0) if_entry.ospfIfRetransInterval = retrans; if (hello >= 0) if_entry.ospfIfHelloInterval = hello; if (rtrdead >= 0) if_entry.ospfIfRtrDeadInterval = rtrdead; ospf_mgr_set_intf(ospf, intf, area, &if_entry, &if_metric); if (!ospf_mgr_enable_intf(intf, ifb, area, 1, MGR_ENTITY_DISABLE)) { fprintf(stderr, "Couldn't enable OSPF INTF for %s\n", s); ospf_mgr_delete_intf(ospf->ipi, intf); continue; } printf(" -- OSPF Interface %s --\n", s); } /* Look for interfaces by IP address */ for (s = INI_ITER_START(courier_section, tag3); s; s = INI_ITER_NEXT()) { if ((argc = parse_line(s, argv, sizeof(argv)/sizeof(*argv))) < 1) { fprintf(stderr, "Couldn't parse %s \"%s\", ignoring\n", tag, s); continue; } MEMSET(&if_entry, 0, sizeof(if_entry)); MEMSET(&if_metric, 0, sizeof(if_metric)); metric = priority = transdly = retrans = hello = rtrdead = -1; switch(argc) { case 7: rtrdead = atoi(argv[6]); case 6: hello = atoi(argv[5]); case 5: retrans = atoi(argv[4]); case 4: transdly = atoi(argv[3]); case 3: priority = atoi(argv[2]); case 2: metric = atoi(argv[1]); default: break; } if (!(ifb = courier_get_ifb(atoinet(argv[0])))) { fprintf(stderr, "Address \"%s\" has no IFB\n", argv[0]); continue; } if (!(intf = ospf_mgr_create_intf(ospf, ifb, area, ifb->ifb_type, 0, 0, 0))) { fprintf(stderr, "Couldn't create OSPF INTF for \"%s\"\n", s); continue; } /* And now we'll try to set some parameters for this interface */ if (ospf_mgr_get_intf_entry(ospf, (void *)intf, GET_THIS, &if_entry, 0) || ospf_mgr_get_if_metric(ospf, (void *)intf, GET_THIS, &if_metric, 0)) continue; if (metric >= 0) if_metric.ospfIfMetricCost = metric; if (priority >= 0) if_entry.ospfIfRtrPriority = priority; if (transdly >= 0) if_entry.ospfIfTransitDelay = transdly; if (retrans >= 0) if_entry.ospfIfRetransInterval = retrans; if (hello >= 0) if_entry.ospfIfHelloInterval = hello; if (rtrdead >= 0) if_entry.ospfIfRtrDeadInterval = rtrdead; ospf_mgr_set_intf(ospf, intf, area, &if_entry, &if_metric); if (!ospf_mgr_enable_intf(intf, ifb, area, 1, MGR_ENTITY_DISABLE)) { fprintf(stderr, "Couldn't enable OSPF INTF for %s\n", s); ospf_mgr_delete_intf(ospf->ipi, intf); continue; } printf(" -- OSPF Interface %s --\n", s); } /* Configure unnumbered interfaces */ for (s = INI_ITER_START(courier_section, tag4); s; s = INI_ITER_NEXT()) { if (!(n = if_lookup(s))) continue; if (!(ifb = n->ifb)) continue; if (!(intf = ospf_mgr_create_intf(ospf, ifb, area, ifb->ifb_type, 0, 0, 0))) { fprintf(stderr, "Couldn't create OSPF INTF for unnumbered %s\n", s); continue; } if (!ospf_mgr_enable_intf(intf, ifb, area, 1, MGR_ENTITY_DISABLE)) { fprintf(stderr, "Couldn't enable OSPF INTF for unnum
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -