summaryrefslogtreecommitdiff
path: root/lib/ofpbuf.c
Commit message (Collapse)AuthorAgeFilesLines
* ofpbuf: Fix offsetting a NULL pointer in ofpbuf_reserve.Ilya Maximets2022-06-241-0/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | | ofpbuf_reserve() can be called with a zero size for a buffer with an unallocated data. It's a valid case, but we should not allow evaluation of 'NULL + 0'. SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior lib/ofpbuf.c:469:30 in lib/ofpbuf.c:469:30: runtime error: applying zero offset to null pointer 0 0xb2f890 in ofpbuf_reserve lib/ofpbuf.c:469:30 1 0xb2f9bc in ofpbuf_new_with_headroom lib/ofpbuf.c:179:5 2 0xb2f9bc in ofpbuf_clone_data_with_headroom lib/ofpbuf.c:228:24 3 0xb2f9bc in ofpbuf_clone_with_headroom lib/ofpbuf.c:199:18 4 0xb2f8ea in ofpbuf_clone lib/ofpbuf.c:189:12 5 0x6b3c57 in ukey_set_actions ofproto/ofproto-dpif-upcall.c:1712:5 6 0x6c4315 in ukey_create__ ofproto/ofproto-dpif-upcall.c:1738:5 7 0x6beed6 in ukey_create_from_upcall ofproto/ofproto-dpif-upcall.c:1793:12 8 0x6beed6 in upcall_xlate ofproto/ofproto-dpif-upcall.c:1284:24 9 0x6beed6 in process_upcall ofproto/ofproto-dpif-upcall.c:1456:9 10 0x6bafb6 in recv_upcalls ofproto/ofproto-dpif-upcall.c:875:17 11 0x6b70fa in udpif_upcall_handler ofproto/ofproto-dpif-upcall.c:792:13 12 0xb4d5fa in ovsthread_wrapper lib/ovs-thread.c:422:12 13 0x7fe6922081ce in start_thread (/lib64/libpthread.so.0+0x81ce) 14 0x7fe690e39dd2 in clone (/lib64/libc.so.6+0x39dd2) Acked-by: Dumitru Ceara <dceara@redhat.com> Acked-by: Aaron Conole <aconole@redhat.com> Signed-off-by: Ilya Maximets <i.maximets@ovn.org>
* ofp-actions: Use aligned structures when decoding ofp actions.Dumitru Ceara2022-05-171-0/+39
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Some openflow actions can be misaligned, e.g., actions whithin OF 1.0 replies to statistics reply messages which have a header of 12 bytes and no additional padding. Also, buggy controllers might incorrectly encode actions. When decoding multiple actions in ofpacts_decode(), make sure that when advancing to the next action it will be properly aligned (multiple of OFPACT_ALIGNTO). Detected by UB Sanitizer when running one of the fuzz tests: lib/ofp-actions.c:5347:12: runtime error: member access within misaligned address 0x0000016ba274 for type 'const struct nx_action_learn', which requires 8 byte alignment 0x0000016ba274: note: pointer points here 20 20 20 20 ff ff 00 38 00 00 23 20 00 10 20 20 ^ 20 20 20 20 20 20 20 20 20 20 20 20 00 03 20 00 0 0x52cece in decode_LEARN_common lib/ofp-actions.c:5347 1 0x52dcf6 in decode_NXAST_RAW_LEARN lib/ofp-actions.c:5463 2 0x548604 in ofpact_decode lib/ofp-actions.inc2:4723 3 0x53ee43 in ofpacts_decode lib/ofp-actions.c:7781 4 0x53efc1 in ofpacts_pull_openflow_actions__ lib/ofp-actions.c:7820 5 0x5409e1 in ofpacts_pull_openflow_instructions lib/ofp-actions.c:8396 6 0x5608a8 in ofputil_decode_flow_stats_reply lib/ofp-flow.c:1100 Acked-by: Adrian Moreno <amorenoz@redhat.com> Acked-by: Aaron Conole <aconole@redhat.com> Signed-off-by: Dumitru Ceara <dceara@redhat.com> Signed-off-by: Ilya Maximets <i.maximets@ovn.org>
* treewide: Avoid offsetting NULL pointers.Dumitru Ceara2022-05-171-0/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This is undefined behavior and was reported by UB Sanitizer: lib/meta-flow.c:3445:16: runtime error: member access within null pointer of type 'struct vl_mf_field' 0 0x6aad0f in mf_get_vl_mff lib/meta-flow.c:3445 1 0x6d96d7 in mf_from_oxm_header lib/nx-match.c:260 2 0x6d9e2e in nx_pull_header__ lib/nx-match.c:341 3 0x6daafa in nx_pull_header lib/nx-match.c:488 4 0x6abcb6 in mf_vl_mff_nx_pull_header lib/meta-flow.c:3605 5 0x73b9be in decode_NXAST_RAW_REG_MOVE lib/ofp-actions.c:2652 6 0x764ccd in ofpact_decode lib/ofp-actions.inc2:4681 [...] lib/sset.c:315:12: runtime error: applying zero offset to null pointer 0 0xcc2e6a in sset_at_position lib/sset.c:315:12 1 0x5734b3 in port_dump_next ofproto/ofproto-dpif.c:4083:20 [...] lib/ovsdb-data.c:2194:56: runtime error: applying zero offset to null pointer 0 0x5e9530 in ovsdb_datum_added_removed lib/ovsdb-data.c:2194:56 1 0x4d6258 in update_row_ref_count ovsdb/transaction.c:335:17 2 0x4c360b in for_each_txn_row ovsdb/transaction.c:1572:33 [...] lib/ofpbuf.c:440:30: runtime error: applying zero offset to null pointer 0 0x75066d in ofpbuf_push_uninit lib/ofpbuf.c:440 1 0x46ac8a in ovnacts_parse lib/actions.c:4190 2 0x46ad91 in ovnacts_parse_string lib/actions.c:4208 3 0x4106d1 in test_parse_actions tests/test-ovn.c:1324 [...] lib/ofp-actions.c:3205:22: runtime error: applying non-zero offset 2 to null pointer 0 0x6e1641 in set_field_split_str lib/ofp-actions.c:3205:22 [...] lib/tnl-ports.c:74:12: runtime error: applying zero offset to null pointer 0 0xceffe7 in tnl_port_cast lib/tnl-ports.c:74:12 1 0xcf14c3 in map_insert lib/tnl-ports.c:116:13 [...] ofproto/ofproto.c:8905:16: runtime error: applying zero offset to null pointer 0 0x556795 in eviction_group_hash_rule ofproto/ofproto.c:8905:16 1 0x503f8d in eviction_group_add_rule ofproto/ofproto.c:9022:42 [...] Also, it's valid to have an empty ofpact list and we should be able to try to iterate through it. UB Sanitizer report: include/openvswitch/ofp-actions.h:222:12: runtime error: applying zero offset to null pointer 0 0x665d69 in ofpact_end ./include/openvswitch/ofp-actions.h:222:12 1 0x66b2cf in ofpacts_put_openflow_actions lib/ofp-actions.c:8861:5 2 0x6ffdd1 in ofputil_encode_flow_mod lib/ofp-flow.c:447:9 [...] Signed-off-by: Dumitru Ceara <dceara@redhat.com> Acked-by: Aaron Conole <aconole@redhat.com> Signed-off-by: Ilya Maximets <i.maximets@ovn.org>
* treewide: Don't pass NULL to library functions that expect non-NULL.Dumitru Ceara2022-02-141-0/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | It's actually undefined behavior to pass NULL to standard library functions that manipulate arrays (e.g., qsort, memcpy, memcmp), even if the passed number of items is 0. UB Sanitizer reports: ovsdb/monitor.c:408:9: runtime error: null pointer passed as argument 1, which is declared to never be null #0 0x406ae1 in ovsdb_monitor_columns_sort ovsdb/monitor.c:408 #1 0x406ae1 in ovsdb_monitor_add ovsdb/monitor.c:1683 [...] lib/ovsdb-data.c:1970:5: runtime error: null pointer passed as argument 2, which is declared to never be null #0 0x4071c8 in ovsdb_datum_push_unsafe lib/ovsdb-data.c:1970 #1 0x471cd0 in ovsdb_datum_apply_diff_in_place lib/ovsdb-data.c:2345 [...] ofproto/ofproto-dpif-rid.c:159:17: runtime error: null pointer passed as argument 1, which is declared to never be null #0 0x4df5d8 in frozen_state_equal ofproto/ofproto-dpif-rid.c:159 #1 0x4dfd27 in recirc_find_equal ofproto/ofproto-dpif-rid.c:179 [...] Acked-by: Aaron Conole <aconole@redhat.com> Signed-off-by: Dumitru Ceara <dceara@redhat.com> Acked-by: Paolo Valerio <pvalerio@redhat.com> Signed-off-by: Ilya Maximets <i.maximets@ovn.org>
* treewide: Clean up inclusions of netdev-dpdk header.Ilya Maximets2019-03-141-1/+0
| | | | | | | | | | 'netdev-dpdk.h' provides only 'netdev_dpdk_register' and 'free_dpdk_buf' which are not used in these files and should not be used. Leftovers from the already removed code. Signed-off-by: Ilya Maximets <i.maximets@samsung.com> Signed-off-by: Ian Stokes <ian.stokes@intel.com>
* ofpbuf: Fix arithmetic error in ofpbuf_insert().Toms Atteka2019-01-181-2/+2
| | | | | | | | | | | memmove byte count was calculated incorrectly as ofpbuf_put_uninit is increasing b->size by n. This patch fixes it by reducing byte count by n. Reported-at: https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=12296 Signed-off-by: Toms Atteka <cpp.code.lv@gmail.com> Signed-off-by: Ben Pfaff <blp@ovn.org>
* ofpbuf: New function ofpbuf_insert().Ben Pfaff2017-06-271-0/+18
| | | | | | This will receive its first users in an upcoming commit. Signed-off-by: Ben Pfaff <blp@ovn.org>
* treewide: Avoid undefined behavior passing null in nonnull parameters.Lance Richardson2017-06-131-1/+1
| | | | | | | | | | Eliminate a number of instances of undefined behavior related to passing NULL in parameters having "nonnull" annotations. Found with gcc's undefined behavior sanitizer. Signed-off-by: Lance Richardson <lrichard@redhat.com> Signed-off-by: Ben Pfaff <blp@ovn.org>
* Move lib/ofpbuf.h to include/openvswitch directoryBen Warren2016-03-301-1/+1
| | | | | | Signed-off-by: Ben Warren <ben@skyportsystems.com> Acked-by: Ryan Moats <rmoats@us.ibm.com> Signed-off-by: Ben Pfaff <blp@ovn.org>
* list: Rename all functions in list.h with ovs_ prefix.Ben Warren2016-03-301-1/+1
| | | | | | | 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>
* ofpbuf: Fix setting of 'msg' in ofpbuf_clone_with_headroom()Jarno Rajahalme2016-03-071-1/+5
| | | | | | | | | | Commit 38876d31 fixed setting 'msg' when resizing an ofpbuf, but failed to fix the same issue in ofpbuf_clone_with_headroom(). Without this fix the newly cloned ofpbuf's 'msg', if non-NULL, will point to the buffer of the original ofpbuf. Signed-off-by: Jarno Rajahalme <jarno@ovn.org> Acked-by: Joe Stringer <joe@ovn.org>
* ofpbuf: Rename 'data_delta' to 'xxx_offset'Jarno Rajahalme2016-03-071-12/+10
| | | | | | | | Using more accurate and descriptive variable names improves code readability. Signed-off-by: Jarno Rajahalme <jarno@ovn.org> Acked-by: Joe Stringer <joe@ovn.org>
* ofpbuf: Make offset calculation more consistent.Jarno Rajahalme2016-03-071-2/+2
| | | | | | | | Use the same method of offset calculation in ofpbuf_clone_with_headroom() as in ofpbuf_resize__(). Signed-off-by: Jarno Rajahalme <jarno@ovn.org> Acked-by: Joe Stringer <joe@ovn.org>
* ofpbuf: Use ptrdiff_t for pointer delta.Joe Stringer2016-03-031-4/+3
| | | | | Signed-off-by: Joe Stringer <joe@ovn.org> Acked-by: Jarno Rajahalme <jarno@ovn.org>
* ofpbuf: Make ofpbuf_put_hex() accept period between hex bytes also.Ben Pfaff2016-02-191-6/+6
| | | | | | | | | This makes it accept the same syntax as parse_NOTE(), so that that function can be simplified. In an upcoming commit a second action will also be able to take advantage of the same feature. Signed-off-by: Ben Pfaff <blp@ovn.org> Acked-by: Jarno Rajahalme <jarno@ovn.org>
* lib/ofpbuf: make ofpbuf_use() staticAndy Zhou2015-09-011-1/+1
| | | | | | | There is no external users for ofpbuf_use() directly. Signed-off-by: Andy Zhou <azhou@nicira.com> Acked-by: Ben Pfaff <blp@nicira.com>
* lib/ofpbuf: add ofpbuf_use_ds() APIAndy Zhou2015-09-011-0/+10
| | | | | | | Add an API to convert a dynamic string object into ofpbuf. Signed-off-by: Andy Zhou <azhou@nicira.com> Acked-by: Ben Pfaff <blp@nicira.com>
* lib/ofpbuf: refactor ofpbuf_use__() APIAndy Zhou2015-09-011-7/+6
| | | | | | | Add the size to its parameter list. Signed-off-by: Andy Zhou <azhou@nicira.com> Acked-by: Ben Pfaff <blp@nicira.com>
* ofpbuf: Update msg when resizing ofpbuf.Alex Wang2015-07-201-4/+21
| | | | | | | | | | | | | | | | | | | | | Commit 6fd6ed7 (ofpbuf: Simplify ofpbuf API.) introduced the 'header' and 'msg' pointers to 'struct ofpbuf'. However, we forget to update the 'msg' pointer when resizing ofpbuf. This bug could cause serious issue. For example, in the function ofputil_encode_nx_packet_in(), the 'msg' pointer is populated in ofpraw_alloc_xid() when creating the ofpbuf . Later, the ofpbuf memory can be reallocated due to the writing to the ofpbuf. However, since the 'msg' pointer is not updated, the later use of the 'ofpbuf->msg' will end up writing to either free'ed memory or memory allocated for other struct. This commit fixes the bug by always updating the 'header' and 'msg' pointers when the ofpbuf is resized. Also, a simple test is added. Signed-off-by: Alex Wang <alexw@nicira.com> Acked-by: Ben Pfaff <blp@nicira.com>
* lib/list: Add LIST_FOR_EACH_POP.Jarno Rajahalme2015-04-061-3/+2
| | | | | | | | Makes popping each member of the list a bit easier. Signed-off-by: Jarno Rajahalme <jrajahalme@nicira.com> Acked-by: Russell Bryant <rbryant@redhat.com> Acked-by: Ben Pfaff <blp@nicira.com>
* ofpbuf: Simplify ofpbuf API.Pravin B Shelar2015-03-031-127/+46
| | | | | | | | | | | | ofpbuf was complicated due to its wide usage across all layers of OVS, Now we have introduced independent dp_packet which can be used for datapath packet, we can simplify ofpbuf. Following patch removes DPDK mbuf and access API of ofpbuf members. Signed-off-by: Pravin B Shelar <pshelar@nicira.com> Acked-by: Jarno Rajahalme <jrajahalme@nicira.com> Acked-by: Ben Pfaff <blp@nicira.com>
* dpif_packet: Rename to dp_packetPravin B Shelar2015-03-031-2/+2
| | | | | | | | dp_packet is short and better name for datapath packet structure. Signed-off-by: Pravin B Shelar <pshelar@nicira.com> Acked-by: Jarno Rajahalme <jrajahalme@nicira.com>
* list: Rename struct list to struct ovs_listThomas Graf2014-12-151-1/+1
| | | | | | | struct list is a common name and can't be used in public headers. Signed-off-by: Thomas Graf <tgraf@noironetworks.com> Acked-by: Ben Pfaff <blp@nicira.com>
* miniflow_extract: Properly handle small IP packets.Jarno Rajahalme2014-11-101-0/+2
| | | | | | | | | | | | | Ethernet frames may contain padding after the IP payload. When parsing IP packets, check the IP total size (IPv4) or IP payload size (IPv6) to detect the size of l2 padding. The l2 padding size is stored in the ofpbuf to prevent ofpbuf_pull from entering the padding, as well as to allow ofpbuf_l4_size() to return the size of the IP payload without the l2 padding. This helps avoiding parsing truncated transport headers, for example. Signed-off-by: Jarno Rajahalme <jrajahalme@nicira.com> Acked-by: Ben Pfaff <blp@nicira.com>
* ofpbuf: Correct the comment for ofpbuf_trim().Wang Sheng-Hui2014-10-061-2/+2
| | | | | | | Headroom and tailroom both are removed. Signed-off-by: Wang Sheng-Hui <shhuiw@gmail.com> Signed-off-by: Ben Pfaff <blp@nicira.com>
* ofpbuf: Correct comment for ofpbuf_reserve_with_tailroom().Wang Sheng-Hui2014-10-061-2/+3
| | | | | | | | Correct the old comment like ofpbuf_reserve() to describe the expected behavior of ofpbuf_reserve_with_tailroom(). Signed-off-by: Wang Sheng-Hui <shhuiw@gmail.com> Signed-off-by: Ben Pfaff <blp@nicira.com>
* netdev-dpdk: Fix race condition with DPDK mempools in non pmd threadsDaniele Di Proietto2014-07-201-4/+0
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | DPDK mempools rely on rte_lcore_id() to implement a thread-local cache. Our non pmd threads had rte_lcore_id() == 0. This allowed concurrent access to the "thread-local" cache, causing crashes. This commit resolves the issue with the following changes: - Every non pmd thread has the same lcore_id (0, for management reasons), which is not shared with any pmd thread (lcore_id for pmd threads now start from 1) - DPDK mbufs must be allocated/freed in pmd threads. When there is the need to use mempools in non pmd threads, like in dpdk_do_tx_copy(), a mutex must be held. - The previous change does not allow us anymore to pass DPDK mbufs to handler threads: therefore this commit partially revert 143859ec63d45e. Now packets are copied for upcall processing. We can remove the extra memcpy by processing upcalls in the pmd thread itself. With the introduction of the extra locking, the packet throughput will be lower in the following cases: - When using internal (tap) devices with DPDK devices on the same datapath. Anyway, to support internal devices efficiently, we needed DPDK KNI devices, which will be proper pmd devices and will not need this locking. - When packets are processed in the slow path by non pmd threads. This overhead can be avoided by handling the upcalls directly in pmd threads (a change that has already been proposed by Ryan Wilson) Also, the following two fixes have been introduced: - In dpdk_free_buf() use rte_pktmbuf_free_seg() instead of rte_mempool_put(). This allows OVS to run properly with CONFIG_RTE_LIBRTE_MBUF_DEBUG DPDK option - Do not bulk free mbufs in a transmission queue. They may belong to different mempools Signed-off-by: Daniele Di Proietto <ddiproietto@vmware.com> Acked-by: Pravin B Shelar <pshelar@nicira.com>
* dpif-netdev: use dpif_packet structure for packetsDaniele Di Proietto2014-06-231-1/+3
| | | | | | | | | | This commit introduces a new data structure used for receiving packets from netdevs and passing them to dpifs. The purpose of this change is to allow storing some private data for each packet. The subsequent commits make use of it. Signed-off-by: Daniele Di Proietto <ddiproietto@vmware.com> Acked-by: Pravin B Shelar <pshelar@nicira.com>
* dpif-netdev: Upcall: Remove an extra memcpy of packet data.Ryan Wilson2014-06-041-1/+10
| | | | | | | | | | | | | | | | | | | | | | | | When a bridge of datatype type netdev receives a packet, it copies the packet from the NIC to a buffer in userspace. Currently, when making an upcall, the packet is again copied to the upcall's buffer. However, this extra copy is not necessary when the datapath exists in userspace as the upcall can directly access the packet data. This patch eliminates this extra copy of the packet data in most cases. In cases where the packet may still be used later by callers of dp_netdev_execute_actions, making a copy of the packet data is still necessary. This patch also adds a dpdk_buf field to 'struct ofpbuf' when using DPDK. This field holds a pointer to the allocated DPDK buffer in the rte_mempool. Thus, an upcall packet ofpbuf allocated on the stack can now share data and free memory of a rte_mempool allocated ofpbuf. Signed-off-by: Ryan Wilson <wryan@nicira.com> Acked-by: Jarno Rajahalme <jrajahalme@nicira.com> Acked-by: Pravin B Shelar <pshelar@nicira.com>
* ofpbuf: Abstract 'l2' pointer and document usage conventions.Jarno Rajahalme2014-04-031-11/+12
| | | | | | | | | | | | | | | | | | | | | | Rename 'l2' to 'frame' and add new ofpbuf_set_frame() and ofpbuf_l2(). ofpbuf_set_frame() alse resets all the layer offsets. ofpbuf_l2() returns NULL if the packet has no Ethernet header, as indicated either by unset l3 offset or NULL frame pointer. Callers of ofpbuf_l2() are supposed to check the return value, unless they can otherwise be sure that the packet has a valid Ethernet header. The recent commit 437d0d22 made some assumptions that were not valid regarding the use of the 'l2' pointer in rconn module and by compose_rarp(). This is now fixed as follows: rconn now relies on the fact that once OpenFlow messages are given to rconn for transport, the frame pointer is no longer needed to refer to the OpenFlow header; and compose_rarp() now sets the frame pointer and offsets as expected. In addition to storing network frames, ofpbufs are also used for handling OpenFlow messages and action lists. lib/ofpbuf.h now has a comment documenting the current usage conventions and invariants. Signed-off-by: Jarno Rajahalme <jrajahalme@nicira.com> Signed-off-by: Ben Pfaff <blp@nicira.com>
* netdev-dpdk: Remove alloc from packet recv.Pravin Shelar2014-03-301-3/+1
| | | | | | | | | | On DPDK packet recv, ovs is given pointer to mbuf which has information about a packet, for example pointer to data and size. By moving mbuf to ofpbuf we can let dpdk allocate ofpbuf and pass that to ovs for processing the packet. Signed-off-by: Pravin B Shelar <pshelar@nicira.com> Acked-by: Jarno Rajahalme <jrajahalme@nicira.com>
* ofpbuf: Add ofpbuf_init_dpdk()Pravin Shelar2014-03-301-5/+23
| | | | | Signed-off-by: Pravin B Shelar <pshelar@nicira.com> Acked-by: Jarno Rajahalme <jrajahalme@nicira.com>
* ofpbuf: Introduce access api for base, data and size.Pravin Shelar2014-03-301-39/+43
| | | | | | | These functions will be used by later patches. Following patch does not change functionality. Signed-off-by: Pravin B Shelar <pshelar@nicira.com>
* lib/ofpbuf: CompactJarno Rajahalme2014-03-291-24/+48
| | | | | | | | | | | | | | | | | | | | | | | | | | | | This patch shrinks the struct ofpbuf from 104 to 48 bytes on 64-bit systems, or from 52 to 36 bytes on 32-bit systems (counting in the 'l7' removal from an earlier patch). This may help contribute to cache efficiency, and will speed up initializing, copying and manipulating ofpbufs. This is potentially important for the DPDK datapath, but the rest of the code base may also see a little benefit. Changes are: - Remove 'l7' pointer (previous patch). - Use offsets instead of layer pointers for l2_5, l3, and l4 using 'l2' as basis. Usually 'data' is the same as 'l2', but this is not always the case (e.g., when parsing or constructing a packet), so it can not be easily used as the offset basis. Also, packet parsing is faster if we do not need to maintain the offsets each time we pull data from the ofpbuf. - Use uint32_t for 'allocated' and 'size', as 2^32 is enough even for largest possible messages/packets. - Use packed enum for 'source'. - Rearrange to avoid unnecessary padding. - Remove 'private_p', which was used only in two cases, both of which had the invariant ('l2' == 'data'), so we can temporarily use 'l2' as a private pointer. Signed-off-by: Jarno Rajahalme <jrajahalme@nicira.com> Signed-off-by: Ben Pfaff <blp@nicira.com>
* lib/ofpbuf: Remove 'l7' pointer.Jarno Rajahalme2014-03-251-7/+1
| | | | | | | | | | | | | Now that we don't need to parse TCP flags from the packet after extraction, we usually do not need the 'l7' pointer any more. When needed, ofpbuf_get_tcp|udp|sctp|icmp_payload() or ofpbuf_get_l4_size() can be used instead. Removal of 'l7' was requested by Pravin for the DPDK datapath work, as it simplifies packet parsing a bit. Signed-off-by: Jarno Rajahalme <jrajahalme@nicira.com> Signed-off-by: Ben Pfaff <blp@nicira.com>
* lib/ofpbuf: Inline the trivial ofpbuf functions.Jarno Rajahalme2014-03-251-98/+0
| | | | | | | | | Inline the most trivial ofpbuf functions to allow for better optimization. Also inline the most often used ofpbuf_pull() and ofpbuf_try_pull(), which should help streamline packet parsing. Signed-off-by: Jarno Rajahalme <jrajahalme@nicira.com> Signed-off-by: Ben Pfaff <blp@nicira.com>
* dpif-netdev: Add DPDK netdev.Pravin2014-03-211-2/+8
| | | | | | | | | | | | | | Following patch adds DPDK netdev-class to userspace datapath. Now OVS can use DPDK port for IO by just configuring DPDK port and then adding dpdk type port to userspace datapath. Refer to INSTALL.DPDK doc for further info. This is based a patch from Gerald Rogers. Signed-off-by: Gerald Rogers <gerald.rogers@intel.com> Signed-off-by: Pravin B Shelar <pshelar@nicira.com> Acked-by: Thomas Graf <tgraf@redhat.com>
* ofpbuf: Add OFPBUF_DPDK type.Pravin2014-03-211-0/+7
| | | | | | This will be used by DPDK for zero copy IO. Signed-off-by: Pravin B Shelar <pshelar@nicira.com>
* ofpbuf: New function ofpbuf_shift().Ben Pfaff2013-12-231-0/+18
| | | | | | An upcoming commit will add the first user. Signed-off-by: Ben Pfaff <blp@nicira.com>
* Rename NOT_REACHED to OVS_NOT_REACHEDHarold Lim2013-12-171-2/+2
| | | | | | | | This allows other libraries to use util.h that has already defined NOT_REACHED. Signed-off-by: Harold Lim <haroldl@vmware.com> Signed-off-by: Ben Pfaff <blp@nicira.com>
* dpif: Allow execute to modify the packet.Jarno Rajahalme2013-12-161-0/+11
| | | | | | | | | | | | | | | | | | | Allowing the packet to be modified by execution allows less data copying for userspace action execution. Some users of the dpif_execute already expect that the packet may be modified. This patch makes this behavior uniform and makes the userspace datapath and the execution helpers modify the packet as it is being executed. Userspace action now steals the packet if given permission, as the packet is normally not needed after it. The only exception is the sample action, and this is accounted for my keeping track of any actions that could be following the userspace action. The packet in dpif_upcall is changed from a pointer to a struct, allowing the packet to be honest about it's headroom. After this change the packet can safely be pushed on over the precarious 4 byte limit earlier allowed by the netlink data preceding the packet. Signed-off-by: Jarno Rajahalme <jrajahalme@nicira.com> Acked-by: Ben Pfaff <blp@nicira.com>
* Avoid printf type modifiers not supported by MSVC C runtime library.Alin Serdean2013-11-251-1/+1
| | | | | | | | | | | | | The MSVC C library printf() implementation does not support the 'z', 't', 'j', or 'hh' format specifiers. This commit changes the Open vSwitch code to avoid those format specifiers, switching to standard macros from <inttypes.h> where available and inventing new macros resembling them where necessary. It also updates CodingStyle to specify the macros' use and adds a Makefile rule to report violations. Signed-off-by: Alin Serdean <aserdean@cloudbasesolutions.com> Co-authored-by: Ben Pfaff <blp@nicira.com> Signed-off-by: Ben Pfaff <blp@nicira.com>
* ofpbuf: Allow whitespace other than spaces in hex data.Ben Pfaff2013-11-051-1/+1
| | | | | | | | It's easier to cut and paste lines of hexadecimal data into a command line if you don't have to worry about new-lines appearing in the command. Signed-off-by: Ben Pfaff <blp@nicira.com> Acked-by: Jarno Rajahalme <jrajahalme@nicira.com>
* ofpbuf: Fix small typo.Justin Pettit2013-05-091-1/+1
| | | | Signed-off-by: Justin Pettit <jpettit@nicira.com>
* ofpbuf: Remove OFPBUF_STACK_BUFFER.Ben Pfaff2013-03-011-3/+3
| | | | | | | Its alleged convenience just doesn't outweigh the syntactical ugliness, and so it didn't have any users. Signed-off-by: Ben Pfaff <blp@nicira.com>
* User-Space MPLS actions and matchesSimon Horman2013-02-051-1/+7
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | This patch implements use-space datapath and non-datapath code to match and use the datapath API set out in Leo Alterman's patch "user-space datapath: Add basic MPLS support to kernel". The resulting MPLS implementation supports: * Pushing a single MPLS label * Poping a single MPLS label * Modifying an MPLS lable using set-field or load actions that act on the label value, tc and bos bit. * There is no support for manipulating the TTL this is considered future work. The single-level push pop limitation is implemented by processing push, pop and set-field/load actions in order and discarding information that would require multiple levels of push/pop to be supported. e.g. push,push -> the first push is discarded pop,pop -> the first pop is discarded This patch is based heavily on work by Ravi K. Cc: Ravi K <rkerur@gmail.com> Reviewed-by: Isaku Yamahata <yamahata@valinux.co.jp> Signed-off-by: Simon Horman <horms@verge.net.au> Signed-off-by: Ben Pfaff <blp@nicira.com>
* Replace most uses of assert by ovs_assert.Ben Pfaff2013-01-161-4/+3
| | | | | | | | This is a straight search-and-replace, except that I also removed #include <assert.h> from each file where there were no assert calls left. Signed-off-by: Ben Pfaff <blp@nicira.com> Acked-by: Ethan Jackson <ethan@nicira.com>
* util: New macro CONST_CAST.Ben Pfaff2012-08-031-2/+2
| | | | | | | | | | | | | | Casts are sometimes necessary. One common reason that they are necessary is for discarding a "const" qualifier. However, this can impede maintenance: if the type of the expression being cast changes, then the presence of the cast can hide a necessary change in the code that does the cast. Using CONST_CAST, instead of a bare cast, makes these changes visible. Inspired by my own work elsewhere: http://git.savannah.gnu.org/cgit/pspp.git/tree/src/libpspp/cast.h#n80 Signed-off-by: Ben Pfaff <blp@nicira.com>
* Global replace of Nicira Networks.Raju Subramanian2012-05-021-1/+1
| | | | | | | | Replaced all instances of Nicira Networks(, Inc) to Nicira, Inc. Feature #10593 Signed-off-by: Raju Subramanian <rsubramanian@nicira.com> Signed-off-by: Ben Pfaff <blp@nicira.com>