From patchwork Fri Oct 23 17:21:23 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Phil Sutter X-Patchwork-Id: 535119 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 C20381401AF for ; Sat, 24 Oct 2015 04:21:30 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752198AbbJWRV0 (ORCPT ); Fri, 23 Oct 2015 13:21:26 -0400 Received: from orbit.nwl.cc ([176.31.251.142]:46063 "EHLO mail.nwl.cc" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752124AbbJWRVZ (ORCPT ); Fri, 23 Oct 2015 13:21:25 -0400 Received: from mail.nwl.cc (orbit [127.0.0.1]) by mail.nwl.cc (Postfix) with ESMTP id 36E02213B6; Fri, 23 Oct 2015 19:21:24 +0200 (CEST) Received: by mail.nwl.cc (Postfix, from userid 1000) id 18032214EA; Fri, 23 Oct 2015 19:21:24 +0200 (CEST) From: Phil Sutter To: Stephen Hemminger Cc: netdev@vger.kernel.org Subject: [iproute PATCH] tc: u32 filter coding style cleanup Date: Fri, 23 Oct 2015 19:21:23 +0200 Message-Id: <1445620883-5304-1-git-send-email-phil@nwl.cc> X-Mailer: git-send-email 2.1.2 X-Virus-Scanned: ClamAV using ClamSMTP Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org Add missing spaces around operators to increase readability. Aside from that, make "preference" match a real synonym for "tos" and "dsfield" as it's effect was identical to them. Signed-off-by: Phil Sutter --- tc/f_u32.c | 56 +++++++++++++++++++++++++++----------------------------- 1 file changed, 27 insertions(+), 29 deletions(-) diff --git a/tc/f_u32.c b/tc/f_u32.c index cb63869..0b97678 100644 --- a/tc/f_u32.c +++ b/tc/f_u32.c @@ -61,14 +61,14 @@ static int get_u32_handle(__u32 *handle, const char *str) if (htid>=0x1000) return -1; if (*tmp) { - str = tmp+1; + str = tmp + 1; hash = strtoul(str, &tmp, 16); if (tmp == str && *str != ':' && *str != 0) return -1; if (hash>=0x100) return -1; if (*tmp) { - str = tmp+1; + str = tmp + 1; nodeid = strtoul(str, &tmp, 16); if (tmp == str && *str != 0) return -1; @@ -124,9 +124,9 @@ static int pack_key(struct tc_u32_sel *sel, __u32 key, __u32 mask, for (i=0; ikeys[i].off == off && sel->keys[i].offmask == offmask) { - __u32 intersect = mask&sel->keys[i].mask; + __u32 intersect = mask & sel->keys[i].mask; - if ((key^sel->keys[i].val) & intersect) + if ((key ^ sel->keys[i].val) & intersect) return -1; sel->keys[i].val |= key; sel->keys[i].mask |= mask; @@ -346,7 +346,7 @@ static int parse_ip_addr(int *argc_p, char ***argv_p, struct tc_u32_sel *sel, mask = 0; if (addr.bitlen) - mask = htonl(0xFFFFFFFF<<(32-addr.bitlen)); + mask = htonl(0xFFFFFFFF << (32 - addr.bitlen)); if (pack_key(sel, addr.data[0], mask, off, offmask) < 0) return -1; res = 0; @@ -381,17 +381,17 @@ static int parse_ip6_addr(int *argc_p, char ***argv_p, } plen = addr.bitlen; - for (i=0; i>16; - hash ^= hash>>8; - htid = ((hash%divisor)<<12)|(htid&0xFFF00000); + hash = sel2.sel.keys[0].val & sel2.sel.keys[0].mask; + hash ^= hash >> 16; + hash ^= hash >> 8; + htid = ((hash % divisor) << 12) | (htid & 0xFFF00000); sample_ok = 1; continue; } else if (strcmp(*argv, "indev") == 0) { @@ -1165,7 +1163,7 @@ static int u32_parse_opt(struct filter_util *qu, char *handle, addattr_l(n, MAX_MSG, TCA_U32_HASH, &htid, 4); if (sel_ok) addattr_l(n, MAX_MSG, TCA_U32_SEL, &sel, - sizeof(sel.sel)+sel.sel.nkeys*sizeof(struct tc_u32_key)); + sizeof(sel.sel) + sel.sel.nkeys * sizeof(struct tc_u32_key)); tail->rta_len = (void *) NLMSG_TAIL(n) - (void *) tail; return 0; } @@ -1173,7 +1171,7 @@ static int u32_parse_opt(struct filter_util *qu, char *handle, static int u32_print_opt(struct filter_util *qu, FILE *f, struct rtattr *opt, __u32 handle) { - struct rtattr *tb[TCA_U32_MAX+1]; + struct rtattr *tb[TCA_U32_MAX + 1]; struct tc_u32_sel *sel = NULL; struct tc_u32_pcnt *pf = NULL; @@ -1209,9 +1207,9 @@ static int u32_print_opt(struct filter_util *qu, FILE *f, struct rtattr *opt, if (tb[TCA_U32_CLASSID]) { SPRINT_BUF(b1); fprintf(f, "%sflowid %s ", - !sel || !(sel->flags&TC_U32_TERMINAL) ? "*" : "", + !sel || !(sel->flags & TC_U32_TERMINAL) ? "*" : "", sprint_tc_classid(rta_getattr_u32(tb[TCA_U32_CLASSID]), b1)); - } else if (sel && sel->flags&TC_U32_TERMINAL) { + } else if (sel && sel->flags & TC_U32_TERMINAL) { fprintf(f, "terminal flowid ??? "); } if (tb[TCA_U32_LINK]) { @@ -1254,16 +1252,16 @@ static int u32_print_opt(struct filter_util *qu, FILE *f, struct rtattr *opt, } } - if (sel->flags&(TC_U32_VAROFFSET|TC_U32_OFFSET)) { + if (sel->flags & (TC_U32_VAROFFSET | TC_U32_OFFSET)) { fprintf(f, "\n offset "); - if (sel->flags&TC_U32_VAROFFSET) + if (sel->flags & TC_U32_VAROFFSET) fprintf(f, "%04x>>%d at %d ", ntohs(sel->offmask), sel->offshift, sel->offoff); if (sel->off) fprintf(f, "plus %d ", sel->off); } - if (sel->flags&TC_U32_EAT) + if (sel->flags & TC_U32_EAT) fprintf(f, " eat "); if (sel->hmask) {