summaryrefslogtreecommitdiff
path: root/ovn/lib/expr.c
Commit message (Collapse)AuthorAgeFilesLines
* expr: Better simplify some special cases of expressions.Ben Pfaff2016-10-111-7/+34
| | | | | | | | | It's pretty unlikely that a human would write expressions like these, but they can come up in machine-generated expressions and it seems best to simplify them in an efficient way. Signed-off-by: Ben Pfaff <blp@ovn.org> Acked-by: Andy Zhou <azhou@ovn.org>
* expr: Fix abort when simplifying "x != 0/0".Ben Pfaff2016-10-111-1/+10
| | | | | | | | | The test added by this commit is very specific to the particular problem, whereas a more general test would be better. A later commit adds the general test. Signed-off-by: Ben Pfaff <blp@ovn.org> Acked-by: Andy Zhou <azhou@ovn.org>
* expr: Simplify "x == 0/0" into 1.Ben Pfaff2016-10-111-1/+14
| | | | | | | | | | | | | | | | | | | | | | | An expression like "x == 0/0" does not test any actual bits in field x, so it resolves to true, but expr_simplify() was not smart enough to see this. This goes beyond an optimization, to become a bug fix, because expr_normalize() will assert-fail for expressions that become trivial when this simplification is omitted. For example: $ echo 'eth.dst == 0/0 && eth.dst == 0/0' | tests/ovstest test-ovn normalize-expr test-ovn: ../include/openvswitch/list.h:245: assertion !ovs_list_is_empty(list) failed in ovs_list_front() Aborted (core dumped) This commit fixes this and related problems. The test added by this commit is very specific to the particular problem, whereas a more general test would be better. A later commit adds the general test. Signed-off-by: Ben Pfaff <blp@ovn.org> Acked-by: Andy Zhou <azhou@ovn.org>
* expr: Fix memory leak in expr_macros_destroy().Ben Pfaff2016-08-311-0/+1
| | | | | | Signed-off-by: Ryan Moats <rmoats@us.ibm.com> [blp@ovn.org split this bug fix out of a larger patch] Signed-off-by: Ben Pfaff <blp@ovn.org>
* expr: New function expr_parse_microflow().Ben Pfaff2016-08-151-0/+121
| | | | | | | | | | | This allows "ovstest test-ovn evaluate-expr" to work with arbitrary microflows rather than just a few restricted variables, but the main point is to enable the upcoming "ovn-trace" utility to accept arbitrary microflows in a format that seems reasonable for OVN. Signed-off-by: Ben Pfaff <blp@ovn.org> Acked-by: Ryan Moats <rmoats@us.ibm.com> Acked-by: Justin Pettit <jpettit@ovn.org>
* expr: New function expr_evaluate().Ben Pfaff2016-08-151-1/+117
| | | | | | | | | | | An upcoming commit will need to evaluate individual expressions outside the context of a classifier. test-ovn already had a function to do this but it wasn't general-purpose, so this commit makes a general-purpose version and adopts it for use in test-ovn as well. Signed-off-by: Ben Pfaff <blp@ovn.org> Acked-by: Ryan Moats <rmoats@us.ibm.com> Acked-by: Justin Pettit <jpettit@ovn.org>
* lex: Integrate error handling into struct lexer.Ben Pfaff2016-08-151-167/+112
| | | | | | | | | | The actions and expr modules had each developed their own error handling code that were very similar. Upcoming code needs similar error handling, so rather than duplicating it again, integrate it into the lexer itself. Signed-off-by: Ben Pfaff <blp@ovn.org> Acked-by: Ryan Moats <rmoats@us.ibm.com> Acked-by: Justin Pettit <jpettit@ovn.org>
* ovn: Rewrite logical action parsing and encoding library.Ben Pfaff2016-08-151-296/+167
| | | | | | | | | | | | | | | | | Until now, parsing logical actions and encoding them into OpenFlow has happened in a single step. An upcoming commit will want to examine actions after parsing without encoding them into OpenFlow. This commit refactors OVN logical actions to make this possible. The new form of the OVN action handling is closely modeled on ofp-actions in the OVS core library. Notable differences are that OVN actions are always fixed-length and that individual OVN actions can have destructors (and thus can contain pointers to data that need to be freed when the actions are destroyed). Signed-off-by: Ben Pfaff <blp@ovn.org> Acked-by: Ryan Moats <rmoats@us.ibm.com> Acked-by: Justin Pettit <jpettit@ovn.org>
* ovn: Use a common symbol table for ovn-controller and test-ovn.Ben Pfaff2016-08-081-0/+32
| | | | | | | | | | | Most of the differences were superficial, so it's better to reduce code duplication. This also adds a test to ensure that the OVN logical registers are built properly out of subfields. Signed-off-by: Ben Pfaff <blp@ovn.org> Acked-by: Ryan Moats <rmoats@us.ibm.com>
* expr: Give a subfield a direct pointer to its parent in struct expr_symbol.Ben Pfaff2016-08-081-43/+27
| | | | | | | | | | | | | | | | | | Until now, symbols that represent subfields and predicates were both implemented as the same string member, named 'expansion', inside struct expr. This makes it a little inconvenient to find the parent of a subfield for two reasons. First, one must actually parse the string, e.g. to convert "vlan.tci[13..15]" into a pointer to a struct. Second, and more importantly, to parse the string it's necessary to have access to the symbol table, which isn't always convenient to pass around. This commit avoids the problem by breaking apart subfields and predicates and giving the former a direct pointer to the parent symbol. We could do the same thing for predicates by storing a pointer to a pre-built struct expr, but so far it's not necessary. Signed-off-by: Ben Pfaff <blp@ovn.org> Acked-by: Ryan Moats <rmoats@us.ibm.com>
* expr: Track writability as part of expr_symbol.Ben Pfaff2016-08-081-5/+8
| | | | | | | | | | Until now it was only possible to find out whether an expr_symbol was read/write or read-only, for subfields, by chasing down whether the eventual parent field was read/write or read-only. This commit adds a new 'rw' member that indicates directly. Signed-off-by: Ben Pfaff <blp@ovn.org> Acked-by: Ryan Moats <rmoats@us.ibm.com>
* expr: Initialize 'relop' of allocated exprs in crush_and_string().Ben Pfaff2016-08-081-0/+1
| | | | | | | | | | Every relop at this point is always EXPR_R_EQ, and therefore it seems that no code actually examined it, so this doesn't appear to fix an existing bug, but some code I was working on was affected by the uninitialized member. Signed-off-by: Ben Pfaff <blp@ovn.org> Acked-by: Ryan Moats <rmoats@us.ibm.com>
* expr: Refine handling of error parameter to expr_annotate().Ben Pfaff2016-08-081-2/+5
| | | | | | | | | | | | In most cases expr_annotate() set '*errorp' to NULL if it was successful, but there was one case where it did not. This corrects that and refines the comment to better explain the intended behavior. This didn't affect any existing users because all of them passed in a pointer that was already NULL. Signed-off-by: Ben Pfaff <blp@ovn.org> Acked-by: Ryan Moats <rmoats@us.ibm.com>
* expr: Tolerate having no macros.Ben Pfaff2016-08-081-1/+3
| | | | | | | A null set of macros seems reasonable, so tolerate it. Signed-off-by: Ben Pfaff <blp@ovn.org> Acked-by: Ryan Moats <rmoats@us.ibm.com>
* expr: Fine-tune parser error message for common typo.Ben Pfaff2016-08-081-2/+5
| | | | | | | | | | | | | | | | | | It's easy to type "=" in place of "==" in an expression but the expression parser's error message was far from clear. For multibit numeric fields, it said: Explicit `!= 0' is required for inequality test of multibit field against 0. For string fields, the parser treated such an expression as "<name> != 0" and thus it said: String field <name> is not compatible with numeric constant. This improves the error message in each case to: Syntax error at `=' expecting relational operator. which I hope to be clear. Signed-off-by: Ben Pfaff <blp@ovn.org> Acked-by: Ryan Moats <rmoats@us.ibm.com>
* ovn: Don't require clearing inport to hair-pin packets.Justin Pettit2016-07-291-10/+0
| | | | | | | | | | | | | | | Introduce the "flags.loopback" symbol to allow packets to be sent back on their ingress ports. Previously, one needed to clear "inport" to hair-pin packets, but this made "inport" not available for future matching. This approach should be more intuitive, but it will also be needed in future patches. This patch also removes functionality from the OVN expression library that clears the OpenFlow ingress port when the logical input port is zeroed. Signed-off-by: Justin Pettit <jpettit@ovn.org> Acked-by: Ben Pfaff <blp@ovn.org>
* move ovn/lib/<lex|actions|expr>.h to include/ovnAaron Rosen2016-07-271-2/+2
| | | | | | | | | | This patch is done to enable in tree building of the ovn-utils python wrapper. This is similar to what was done in commit ee89ea7b477bb4fd05137de03b2e8443807ed9f4 (json: Move from lib to include/openvswitch.). Signed-off-by: Aaron Rosen <aaronorosen@gmail.com> Signed-off-by: Ben Pfaff <blp@ovn.org>
* json: Move from lib to include/openvswitch.Terry Wilson2016-07-221-2/+3
| | | | | | | | | | | | | | | To easily allow both in- and out-of-tree building of the Python wrapper for the OVS JSON parser (e.g. w/ pip), move json.h to include/openvswitch. This also requires moving lib/{hmap,shash}.h. Both hmap.h and shash.h were #include-ing "util.h" even though the headers themselves did not use anything from there, but rather from include/openvswitch/util.h. Fixing that required including util.h in several C files mostly due to OVS_NOT_REACHED and things like xmalloc. Signed-off-by: Terry Wilson <twilson@redhat.com> Signed-off-by: Ben Pfaff <blp@ovn.org>
* ovn: Add address set support.Russell Bryant2016-07-021-6/+107
| | | | | | | | | | | | | | | | | | | | | | | | | | Update the OVN expression parser to support address sets. Previously, you could have a set of IP or MAC addresses in this form: {addr1, addr2, ..., addrN} This patch adds support for a bit of indirection where we can define a set of addresses and refer to them by name. $name This '$name' can be used in the expresssions like {addr1, addr2, $name, ... } {$name} $name A future patch will expose the ability to define address sets for use. Signed-off-by: Russell Bryant <russell@ovn.org> Co-authored-by: Babu Shanmugam <bschanmu@redhat.com> Signed-off-by: Babu Shanmugam <bschanmu@redhat.com> [blp@ovn.org made numerous small changes] Signed-off-by: Ben Pfaff <blp@ovn.org>
* ovn-controller: Add 'put_dhcp_opts' action in ovn-controllerNuman Siddique2016-06-231-35/+10
| | | | | | | | | | | | | | | | | | | | | | | | | | | | This patch adds a new OVN action 'put_dhcp_opts' to support native DHCP in OVN. ovn-controller parses this action and adds a NXT_PACKET_IN2 OF flow with 'pause' flag set and the DHCP options stored in 'userdata' field. When the valid DHCP packet is received by ovn-controller, it frames a new DHCP reply packet with the DHCP options present in the 'userdata' field and resumes the packet and stores 1 in the 1-bit subfield. If the packet is invalid, it resumes the packet without any modifying and stores 0 in the 1-bit subfield. Eg. reg0[0] = put_dhcp_opts(offerip = 10.0.0.4, router = 10.0.0.1, netmask = 255.255.255.0, lease_time = 3600,....) A new 'DHCP_Options' table is added in SB DB which stores the supported DHCP options with DHCP code and type. ovn-northd is expected to popule this table. The next patch will add logical flows with this action. Signed-off-by: Numan Siddique <nusiddiq@redhat.com> Co-authored-by: Ben Pfaff <blp@ovn.org> Signed-off-by: Ben Pfaff <blp@ovn.org>
* expr: Refactor parsing of assignments and exchanges.Ben Pfaff2016-06-231-75/+98
| | | | | | | | | | As written, it was difficult for the OVN logical action code to add support for new actions of the form "dst = ...", because the code to parse the left side of the assignment was a monolithic part of the expr library. This commit refactors the code division so that an upcoming patch can support a new "dst = func(args);" kind of action. Signed-off-by: Ben Pfaff <blp@ovn.org>
* expr: Shorten declarations of expr_context.Ben Pfaff2016-06-231-24/+4
| | | | | | | Seems to me that this makes the code slightly easier to follow. Signed-off-by: Ben Pfaff <blp@ovn.org> Acked-by: Ryan Moats <rmoats@us.ibm.com>
* hmap: Add HMAP_FOR_EACH_POP.Daniele Di Proietto2016-04-261-3/+2
| | | | | | | Makes popping each member of the hmap a bit easier. Signed-off-by: Daniele Di Proietto <diproiettod@vmware.com> Acked-by: Ben Pfaff <blp@ovn.org>
* Move lib/ofp-actions.h to include/openvswitch directoryBen Warren2016-04-141-3/+3
| | | | | Signed-off-by: Ben Warren <ben@skyportsystems.com> Signed-off-by: Ben Pfaff <blp@ovn.org>
* Move lib/ofp-util.h to include/openvswitch directoryBen Warren2016-04-141-0/+1
| | | | | | | | This commit also adds several #include directives in source files in order to make the 'ofp-util.h' move possible Signed-off-by: Ben Warren <ben@skyportsystems.com> Signed-off-by: Ben Pfaff <blp@ovn.org>
* Move lib/match.h to include/openvswitch directoryBen Warren2016-04-141-1/+1
| | | | | Signed-off-by: Ben Warren <ben@skyportsystems.com> Signed-off-by: Ben Pfaff <blp@ovn.org>
* list: Rename all functions in list.h with ovs_ prefix.Ben Warren2016-03-301-69/+69
| | | | | | | This attempts to prevent namespace collisions with other list libraries Signed-off-by: Ben Warren <ben@skyportsystems.com> Signed-off-by: Ben Pfaff <blp@ovn.org>
* Move lib/dynamic-string.h to include/openvswitch directoryBen Warren2016-03-191-1/+1
| | | | | Signed-off-by: Ben Warren <ben@skyportsystems.com> Signed-off-by: Ben Pfaff <blp@ovn.org>
* ovn: Implement basic ARP support for L3 logical routers.Ben Pfaff2016-03-121-0/+53
| | | | | | | | | | | | | | | This is sufficient support that an L3 logical router can now transmit packets to VMs (and other destinations) without having to know the IP-to-MAC binding in advance. The details are carefully documented in all of the appropriate places. There are several important caveats that need to be fixed before this can be taken seriously in production. These are documented in ovn/TODO. The most important of these are renewal, expiration, and limiting the size of the ARP table. Signed-off-by: Ben Pfaff <blp@ovn.org> Acked-by: Justin Pettit <jpettit@ovn.org>
* ovn: Use callback function instead of simap for logical port number map.Ben Pfaff2016-03-111-36/+58
| | | | | | | | | | | | | An simap is convenient but it isn't very flexible. If the client wants to keep extra data with each node then it has to build a second parallel data structure. A callback function is kind of a pain for the clients from the point of view of having to write it and deal with auxiliary data, etc., but it allows the storage to be more flexible. An upcoming commit will make further use of this capability. Signed-off-by: Ben Pfaff <blp@ovn.org> Acked-by: Justin Pettit <jpettit@ovn.org>
* expr: Generalize wording of error message in expand_symbol().Ben Pfaff2016-02-191-8/+5
| | | | | | | | | | | The existing wording was very specific to the actual operation being performed. While this is nice for users, it becomes difficult to maintain as more and more operations are added. This commit makes the wording less specific, because a third operation will start using this function in an upcoming commit. Signed-off-by: Ben Pfaff <blp@ovn.org> Acked-by: Justin Pettit <jpettit@ovn.org>
* expr: Fix memory leak reported by valgrind.William Tu2016-02-111-3/+3
| | | | | | | | | | | | | | | Testcase 1728: ovn -- 5-term mixed expression normalization. expr_clone_cmp (expr.c:1259) expr_clone (expr.c:1284) expr_clone_andor (expr.c:1271) expr_clone (expr.c:1288) expr_normalize_and (expr.c:2137) test_tree_shape_exhaustively (test-ovn.c:926) Signed-off-by: William Tu <u9012063@gmail.com> Signed-off-by: Daniele Di Proietto <diproiettod@vmware.com> Co-authored-by: Daniele Di Proietto <diproiettod@vmware.com> Signed-off-by: Russell Bryant <russell@ovn.org>
* expr: Fix memory leak reported by valgrind.William Tu2016-02-111-0/+1
| | | | | | | | | | | | | | | Testcase 1728: ovn -- 5-term mixed expression normalization Call stack: sset_add__ (sset.c:53) crush_and_string (expr.c:1725) crush_cmps (expr.c:1998) expr_sort (expr.c:2050) expr_normalize_and (expr.c:2085) Signed-off-by: William Tu <u9012063@gmail.com> Signed-off-by: Daniele Di Proietto <diproiettod@vmware.com> Co-authored-by: Daniele Di Proietto <diproiettod@vmware.com> Signed-off-by: Russell Bryant <russell@ovn.org>
* ovn: Implement the ability to send a packet back out its input port.Ben Pfaff2015-10-191-2/+12
| | | | | | | Otherwise logical router ARP replies won't work as implemented. Signed-off-by: Ben Pfaff <blp@nicira.com> Acked-by: Justin Pettit <jpettit@nicira.com>
* ovn: Extend logical "next" action to jump to arbitrary flow tables.Ben Pfaff2015-10-151-8/+3
| | | | | | | | | This makes it easier to route a "destination unreachable" message generated because of an IP routing failure, because the destination unreachable message must itself be routed the same way. Signed-off-by: Ben Pfaff <blp@nicira.com> Acked-by: Justin Pettit <jpettit@nicira.com>
* expr: Document error handling for expr_annotate().Justin Pettit2015-10-131-1/+4
| | | | | Signed-off-by: Justin Pettit <jpettit@nicira.com> Acked-by: Ben Pfaff <blp@nicira.com>
* ovn: Implement action to exchange two fields.Ben Pfaff2015-10-071-29/+79
| | | | | Signed-off-by: Ben Pfaff <blp@nicira.com> Acked-by: Justin Pettit <jpettit@nicira.com>
* ovn: Implement action to copy one field into another.Ben Pfaff2015-10-071-67/+119
| | | | | Signed-off-by: Ben Pfaff <blp@nicira.com> Acked-by: Justin Pettit <jpettit@nicira.com>
* expr: Properly handle several cases involving string variables.Ben Pfaff2015-09-111-17/+143
| | | | | | | | | | The expr test cases covered string variables poorly and thus a number of bugs and omissions slipped through. This fixes them and generalizes the test cases to better cover string variables. Reported-by: Justin Pettit <jpettit@nicira.com> Signed-off-by: Ben Pfaff <blp@nicira.com> Acked-by: Justin Pettit <jpettit@nicira.com>
* expr: Add and clarify a few comments and assertions.Ben Pfaff2015-08-261-4/+15
| | | | | Signed-off-by: Ben Pfaff <blp@nicira.com> Acked-by: Justin Pettit <jpettit@nicira.com>
* ovn: Fix example in comment in expr.c.Justin Pettit2015-08-251-1/+1
| | | | | Signed-off-by: Justin Pettit <jpettit@nicira.com> Acked-by: Russell Bryant <rbryant@redhat.com>
* ovn: Fix extra token detection.Joe Stringer2015-07-171-1/+1
| | | | | | | | | | | | | | | | This code attempts to first check whether another error was detected for the string it is parsing, then if it's not at the end of the tokens, report an error. However, 'errorp' is always a valid pointer to a 'char *', so the first check in this statement always evaluates false. Furthermore, this undefined behaviour may be optimised out by modern compilers due to the prior dereference in expr_parse(). Fix this to check the actual value of *errorp. Also add a test to check this case. Found by MIT STACK undefined behaviour checker. Signed-off-by: Joe Stringer <joestringer@nicira.com> Acked-by: Ben Pfaff <blp@nicira.com>
* ovn: New module for parsing OVN actions as OpenFlow.Ben Pfaff2015-05-031-18/+161
| | | | | Signed-off-by: Ben Pfaff <blp@nicira.com> Acked-by: Justin Pettit <jpettit@nicira.com>
* expr: Make expr_to_flows() include conj_id flows.Ben Pfaff2015-04-291-0/+18
| | | | | | | | | | | | | When I wrote expr_to_flows() originally, I assumed that the caller could simply add an appropriate conj_id=X flow for each of the conjunctive matches. I forgot that the conj_id=X flows also need to include prerequisites for actions, e.g. if the OpenFlow actions manipulate TCP fields, then the conj_id=X field must match on eth_type=0x800 and ip_proto=6. That's hard for the caller to generate itself, so this commit changes expr_to_matches() to generate the conj_id=X flows also. Signed-off-by: Ben Pfaff <blp@nicira.com> Acked-by: Justin Pettit <jpettit@nicira.com>
* json: New function json_string_escape().Ben Pfaff2015-04-201-11/+1
| | | | | | | | This saves some cut-and-paste duplicated code elsewhere and will have additional users in upcoming commits. Signed-off-by: Ben Pfaff <blp@nicira.com> Acked-by: Russell Bryant <rbryant@redhat.com>
* expr: Support string fields in expr_to_matches().Ben Pfaff2015-04-161-28/+136
| | | | | Signed-off-by: Ben Pfaff <blp@nicira.com> Acked-by: Russell Bryant <rbryant@redhat.com>
* expr: New module for Boolean expressions on fields, for use in OVN.Ben Pfaff2015-04-151-0/+2351
Known weaknesses: * String fields can't be converted to flows yet. A subsequent commit will fix this. * Flows aren't optimal in some situations likely to be common. I don't think either of those is a reason not to commit this; this is a solid base to build on. Signed-off-by: Ben Pfaff <blp@nicira.com> Acked-by: Russell Bryant <rbryant@redhat.com>