X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=utilities%2Fovs-ofctl.c;h=10b31537144c7dbaa0a51477e81c4855b9ad3d20;hb=356180a825c94314f3d1667003e64526d1b69da5;hp=e7997c61e82b95639851baa67e424fbc785e071b;hpb=0199c526f17c7dbed579436f716a1feae22e192a;p=openvswitch diff --git a/utilities/ovs-ofctl.c b/utilities/ovs-ofctl.c index e7997c61..10b31537 100644 --- a/utilities/ovs-ofctl.c +++ b/utilities/ovs-ofctl.c @@ -633,56 +633,67 @@ check_final_format_for_flow_mod(enum nx_flow_format flow_format) } static void -do_flow_mod__(int argc OVS_UNUSED, char *argv[], uint16_t command) +do_flow_mod_file__(int argc OVS_UNUSED, char *argv[], uint16_t command) { enum nx_flow_format flow_format; struct list requests; struct vconn *vconn; + FILE *file; + + file = !strcmp(argv[2], "-") ? stdin : fopen(argv[2], "r"); + if (file == NULL) { + ovs_fatal(errno, "%s: open", argv[2]); + } list_init(&requests); flow_format = set_initial_format_for_flow_mod(&requests); - parse_ofp_flow_mod_str(&requests, &flow_format, argc > 2 ? argv[2] : "", - command); - check_final_format_for_flow_mod(flow_format); - open_vconn(argv[1], &vconn); - transact_multiple_noreply(vconn, &requests); + while (parse_ofp_flow_mod_file(&requests, &flow_format, file, command)) { + check_final_format_for_flow_mod(flow_format); + transact_multiple_noreply(vconn, &requests); + } vconn_close(vconn); -} -static void -do_add_flow(int argc, char *argv[]) -{ - do_flow_mod__(argc, argv, OFPFC_ADD); + if (file != stdin) { + fclose(file); + } } static void -do_add_flows(int argc OVS_UNUSED, char *argv[]) +do_flow_mod__(int argc, char *argv[], uint16_t command) { enum nx_flow_format flow_format; struct list requests; struct vconn *vconn; - FILE *file; - file = !strcmp(argv[2], "-") ? stdin : fopen(argv[2], "r"); - if (file == NULL) { - ovs_fatal(errno, "%s: open", argv[2]); + if (argc > 2 && !strcmp(argv[2], "-")) { + do_flow_mod_file__(argc, argv, command); + return; } list_init(&requests); flow_format = set_initial_format_for_flow_mod(&requests); + parse_ofp_flow_mod_str(&requests, &flow_format, argc > 2 ? argv[2] : "", + command); + check_final_format_for_flow_mod(flow_format); + open_vconn(argv[1], &vconn); - while (parse_ofp_add_flow_file(&requests, &flow_format, file)) { - check_final_format_for_flow_mod(flow_format); - transact_multiple_noreply(vconn, &requests); - } + transact_multiple_noreply(vconn, &requests); vconn_close(vconn); +} - if (file != stdin) { - fclose(file); - } +static void +do_add_flow(int argc, char *argv[]) +{ + do_flow_mod__(argc, argv, OFPFC_ADD); +} + +static void +do_add_flows(int argc, char *argv[]) +{ + do_flow_mod_file__(argc, argv, OFPFC_ADD); } static void @@ -1339,7 +1350,7 @@ do_parse_flows(int argc OVS_UNUSED, char *argv[]) } list_init(&packets); - while (parse_ofp_add_flow_file(&packets, &flow_format, file)) { + while (parse_ofp_flow_mod_file(&packets, &flow_format, file, OFPFC_ADD)) { print_packet_list(&packets); } fclose(file);