From patchwork Wed Feb 29 16:34:28 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Danilov X-Patchwork-Id: 143779 X-Patchwork-Delegate: shemminger@vyatta.com Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id B881DB6EEC for ; Thu, 1 Mar 2012 03:34:31 +1100 (EST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1758183Ab2B2Qea (ORCPT ); Wed, 29 Feb 2012 11:34:30 -0500 Received: from mail-ww0-f44.google.com ([74.125.82.44]:57864 "EHLO mail-ww0-f44.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756670Ab2B2Qe3 (ORCPT ); Wed, 29 Feb 2012 11:34:29 -0500 Received: by wgbdr13 with SMTP id dr13so3917147wgb.1 for ; Wed, 29 Feb 2012 08:34:28 -0800 (PST) Received-SPF: pass (google.com: domain of littlesmilingcloud@gmail.com designates 10.180.14.73 as permitted sender) client-ip=10.180.14.73; Authentication-Results: mr.google.com; spf=pass (google.com: domain of littlesmilingcloud@gmail.com designates 10.180.14.73 as permitted sender) smtp.mail=littlesmilingcloud@gmail.com; dkim=pass header.i=littlesmilingcloud@gmail.com Received: from mr.google.com ([10.180.14.73]) by 10.180.14.73 with SMTP id n9mr2362060wic.16.1330533268310 (num_hops = 1); Wed, 29 Feb 2012 08:34:28 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=mime-version:date:message-id:subject:from:to:content-type; bh=d2iE3T7632wrxdgeAmCWLyPpm8LuKFZFP0eKneAMEp8=; b=HdWx617P+pcSBVysiv/QxWvAMGQ9+/9QfjpQvYUxlM1gawFl0KiPKWQQMqHNhZnTFW sGVRzt07LaQNvVJLHaD4s6SsAppoKLsgEqHNxVk4PlFcz+cGZHAOhBJsd9K7GwKsCEV2 f6oStPS41WiJ9VfRQYf1Bb4dosZsK0fyBXfCc= MIME-Version: 1.0 Received: by 10.180.14.73 with SMTP id n9mr1898703wic.16.1330533268265; Wed, 29 Feb 2012 08:34:28 -0800 (PST) Received: by 10.180.107.136 with HTTP; Wed, 29 Feb 2012 08:34:28 -0800 (PST) Date: Wed, 29 Feb 2012 19:34:28 +0300 Message-ID: Subject: [PATCH iproute] tc pedit action: fix parsing offset options. From: "Anton 'EvilMan' Danilov" To: netdev@vger.kernel.org Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org This patch fix parsing offset option with "at" parameter. Tc returns error If keywords "offmask" and "shift" are presented. Example of wrong parsing: ~$ tc f add dev eth0 parent 1: protocol ip pref 10 \ u32 match u32 0 0 \ action pedit help Usage: ... pedit munge Where: MUNGE := | := [ATC] OFFSETC:= offset ATC:= at offmask shift NOTE: offval is byte offset, must be multiple of 4 NOTE: maskval is a 32 bit hex number NOTE: shiftval is a is a shift value CMD:= clear | invert | set | retain := ip | ip6 | udp | tcp | icmp For Example usage look at the examples directory #try to add filter with pedit action using "at" option ~$ tc f add dev eth0 parent 1: pref 10 protocol all handle ::10 \ u32 match ip protocol 6 0xff \ match ip src 10.10.20.119/32 \ match ip dst 10.10.20.254/32 \ action pedit munge offset 2 u16 at 0 offmask 0f0000000 shift 22 set 11500 Illegal pedit construct (2) ... bad action parsing parse_action: bad value (19:pedit)! Illegal "action" ~$ tc f add dev eth0 parent 1: pref 10 protocol all handle ::10 \ u32 match ip protocol 6 0xff \ match ip src 10.10.20.119/32 \ match ip dst 10.10.20.254/32 \ action pedit munge offset 2 u16 at 0 0f0000000 22 set 11500 parse_cmd argc 8 set offset 2 length 2 pack_key16: Final val ec2c0000 mask 0000ffff parse_cmd done argc 6 pipe offset 0 length 2 + NEXT_ARG(); + if (get_u32(&shift, *argv, 0)) + return -1; + tkey->shift = shift; + } else { return -1; - tkey->shift = shift; + } NEXT_ARG(); } diff --git a/tc/m_pedit.c b/tc/m_pedit.c index 7499846..fa56234 100644 --- a/tc/m_pedit.c +++ b/tc/m_pedit.c @@ -390,16 +390,24 @@ done: tkey->at = atv; NEXT_ARG(); - - if (get_u32(&offmask, *argv, 16)) + if (matches(*argv, "offmask") == 0) { + NEXT_ARG(); + if (get_u32(&offmask, *argv, 16)) + return -1; + tkey->offmask = htonl(offmask); + } else { return -1; - tkey->offmask = offmask; + } NEXT_ARG(); - - if (get_u32(&shift, *argv, 0)) + if (matches(*argv, "shift") == 0) { + NEXT_ARG(); + if (get_u32(&shift, *argv, 0)) + return -1; + tkey->shift = shift; + } else { return -1; - tkey->shift = shift; + } NEXT_ARG(); - - if (get_u32(&shift, *argv, 0)) + if (matches(*argv, "shift") == 0) {