Example #1
0
void
test_match_basic_IPV4_DST_W(void) {
  struct lagopus_packet *pkt;
  struct port port;
  struct flow *flow;
  OS_MBUF *m;
  bool rv;

  /* prepare packet */
  pkt = alloc_lagopus_packet();
  TEST_ASSERT_NOT_NULL_MESSAGE(pkt, "lagopus_alloc_packet error.");
  m = pkt->mbuf;
  OS_M_APPEND(m, 64);

  /* prepare flow */
  flow = calloc(1, sizeof(struct flow) + 10 * sizeof(struct match));
  TAILQ_INIT(&flow->match_list);

  add_match(&flow->match_list, 2, OFPXMT_OFB_ETH_TYPE << 1,
            0x08, 0x00);
  OS_MTOD(m, uint8_t *)[12] = 0x81;
  OS_MTOD(m, uint8_t *)[13] = 0x00;
  OS_MTOD(m, uint8_t *)[16] = 0x08;
  OS_MTOD(m, uint8_t *)[17] = 0x00;
  OS_MTOD(m, uint8_t *)[18] = 0x45;
  /* IP dst */
  add_match(&flow->match_list, 8, (OFPXMT_OFB_IPV4_DST << 1) + 1,
            192, 168, 0, 0, 255, 255, 255, 0);
  OS_MTOD(m, uint8_t *)[34] = 192;
  OS_MTOD(m, uint8_t *)[35] = 168;
  OS_MTOD(m, uint8_t *)[36] = 1;
  OS_MTOD(m, uint8_t *)[37] = 2;
  refresh_match(flow);
  lagopus_packet_init(pkt, m, &port);
  rv = match_basic(pkt, flow);
  TEST_ASSERT_EQUAL_MESSAGE(rv, false,
                            "IPV4_DST_W mismatch(1) error.");
  OS_MTOD(m, uint8_t *)[34] = 2;
  OS_MTOD(m, uint8_t *)[35] = 0;
  OS_MTOD(m, uint8_t *)[36] = 168;
  OS_MTOD(m, uint8_t *)[37] = 192;
  lagopus_packet_init(pkt, m, &port);
  rv = match_basic(pkt, flow);
  TEST_ASSERT_EQUAL_MESSAGE(rv, false,
                            "IPV4_DST_W mismatch(2) error.");
  OS_MTOD(m, uint8_t *)[34] = 192;
  OS_MTOD(m, uint8_t *)[35] = 168;
  OS_MTOD(m, uint8_t *)[36] = 0;
  OS_MTOD(m, uint8_t *)[37] = 2;
  lagopus_packet_init(pkt, m, &port);
  rv = match_basic(pkt, flow);
  TEST_ASSERT_EQUAL_MESSAGE(rv, true,
                            "IPV4_DST_W match error.");
}
void
test_match_basic_IPV6_ND_SLL(void) {
  struct lagopus_packet pkt;
  struct port port;
  struct flow *flow;
  OS_MBUF *m;
  bool rv;
  int i;

  /* prepare packet */
  pkt.in_port = &port;
  m = calloc(1, sizeof(*m));
  TEST_ASSERT_NOT_NULL_MESSAGE(m, "calloc error.");
  m->data = &m->dat[128];
  OS_M_PKTLEN(m) = 128;

  /* prepare flow */
  flow = calloc(1, sizeof(struct flow) + 10 * sizeof(struct match));
  TAILQ_INIT(&flow->match_list);

  add_match(&flow->match_list, 2, OFPXMT_OFB_ETH_TYPE << 1,
            0x86, 0xdd);

  /* IP proto */
  add_match(&flow->match_list, 1, OFPXMT_OFB_IP_PROTO << 1,
            IPPROTO_ICMPV6);

  m->data[12] = 0x86;
  m->data[13] = 0xdd;
  m->data[19] = 0x80; /* PLEN */
  m->data[20] = IPPROTO_ICMPV6;
  m->data[54] = ND_NEIGHBOR_SOLICIT;
  m->data[78] = ND_OPT_SOURCE_LINKADDR;
  m->data[79] = 1;
  m->data[86] = ND_OPT_TARGET_LINKADDR;
  m->data[87] = 1;
  add_match(&flow->match_list, ETH_ALEN, OFPXMT_OFB_IPV6_ND_SLL << 1,
            0xe0, 0x4d, 0x01, 0x34, 0x56, 0x78);
  refresh_match(flow);
  lagopus_packet_init(&pkt, m);
  rv = match_basic(&pkt, flow);
  TEST_ASSERT_EQUAL_MESSAGE(rv, false,
                            "IPV6_ND_SLL mismatch error.");
  i = 80;
  m->data[i++] = 0xe0;
  m->data[i++] = 0x4d;
  m->data[i++] = 0x01;
  m->data[i++] = 0x34;
  m->data[i++] = 0x56;
  m->data[i++] = 0x78;
  rv = match_basic(&pkt, flow);
  TEST_ASSERT_EQUAL_MESSAGE(rv, true,
                            "IPV6_ND_SLL match error.");
}
Example #3
0
void
test_match_basic_IPV6_ND_TLL(void) {
  struct lagopus_packet *pkt;
  struct port port;
  struct flow *flow;
  OS_MBUF *m;
  bool rv;
  int i;

  /* prepare packet */
  pkt = alloc_lagopus_packet();
  TEST_ASSERT_NOT_NULL_MESSAGE(pkt, "lagopus_alloc_packet error.");
  m = pkt->mbuf;
  OS_M_PKTLEN(m) = 128;

  /* prepare flow */
  flow = calloc(1, sizeof(struct flow) + 10 * sizeof(struct match));
  TAILQ_INIT(&flow->match_list);

  add_match(&flow->match_list, 2, OFPXMT_OFB_ETH_TYPE << 1,
            0x86, 0xdd);

  /* IP proto */
  add_match(&flow->match_list, 1, OFPXMT_OFB_IP_PROTO << 1,
            IPPROTO_ICMPV6);

  OS_MTOD(m, uint8_t *)[12] = 0x86;
  OS_MTOD(m, uint8_t *)[13] = 0xdd;
  OS_MTOD(m, uint8_t *)[19] = 0x80; /* PLEN */
  OS_MTOD(m, uint8_t *)[20] = IPPROTO_ICMPV6;
  OS_MTOD(m, uint8_t *)[54] = ND_NEIGHBOR_ADVERT;
  OS_MTOD(m, uint8_t *)[78] = ND_OPT_SOURCE_LINKADDR;
  OS_MTOD(m, uint8_t *)[79] = 1;
  OS_MTOD(m, uint8_t *)[86] = ND_OPT_TARGET_LINKADDR;
  OS_MTOD(m, uint8_t *)[87] = 1;
  add_match(&flow->match_list, ETH_ALEN, OFPXMT_OFB_IPV6_ND_TLL << 1,
            0xe0, 0x4d, 0x01, 0x34, 0x56, 0x78);
  refresh_match(flow);
  lagopus_packet_init(pkt, m, &port);
  rv = match_basic(pkt, flow);
  TEST_ASSERT_EQUAL_MESSAGE(rv, false,
                            "IPV6_ND_TLL mismatch error.");
  i = 88;
  OS_MTOD(m, uint8_t *)[i++] = 0xe0;
  OS_MTOD(m, uint8_t *)[i++] = 0x4d;
  OS_MTOD(m, uint8_t *)[i++] = 0x01;
  OS_MTOD(m, uint8_t *)[i++] = 0x34;
  OS_MTOD(m, uint8_t *)[i++] = 0x56;
  OS_MTOD(m, uint8_t *)[i++] = 0x78;
  rv = match_basic(pkt, flow);
  TEST_ASSERT_EQUAL_MESSAGE(rv, true,
                            "IPV6_ND_TLL match error.");
}
Example #4
0
void
test_match_basic_IPV6_EXTHDR_W(void) {
  struct lagopus_packet pkt;
  struct port port;
  struct flow *flow;
  OS_MBUF *m;
  bool rv;

  /* prepare packet */
  pkt.in_port = &port;
  m = calloc(1, sizeof(*m));
  TEST_ASSERT_NOT_NULL_MESSAGE(m, "calloc error.");
  m->data = &m->dat[128];
  OS_M_PKTLEN(m) = 128;

  /* prepare flow */
  flow = calloc(1, sizeof(struct flow) + 10 * sizeof(struct match));
  TAILQ_INIT(&flow->match_list);

  add_match(&flow->match_list, 2, OFPXMT_OFB_ETH_TYPE << 1,
            0x86, 0xdd);
  m->data[12] = 0x86;
  m->data[13] = 0xdd;
  add_match(&flow->match_list, 1, OFPXMT_OFB_IP_PROTO << 1,
            IPPROTO_TCP);
  m->data[20] = IPPROTO_DSTOPTS;
  m->data[54] = IPPROTO_TCP;
  m->data[55] = 4;
  add_match(&flow->match_list, 4, (OFPXMT_OFB_IPV6_EXTHDR << 1) + 1,
            OFPIEH_UNSEQ >> 8, 0,
            OFPIEH_UNSEQ >> 8, OFPIEH_UNREP);
  refresh_match(flow);
  lagopus_packet_init(&pkt, m);
  rv = match_basic(&pkt, flow);
  TEST_ASSERT_EQUAL_MESSAGE(rv, false,
                            "IPV6_EXTHDR_W mismatch error.");
  m->data[54] = IPPROTO_HOPOPTS;
  m->data[55] = 0;
  m->data[62] = IPPROTO_ESP;
  m->data[63] = 0;
  m->data[70] = IPPROTO_AH;
  m->data[72] = 0;
  m->data[78] = IPPROTO_ROUTING;
  m->data[79] = 0;
  m->data[86] = IPPROTO_FRAGMENT;
  m->data[94] = IPPROTO_NONE;
  m->data[95] = 0;
  m->data[102] = IPPROTO_TCP;
  lagopus_packet_init(&pkt, m);
  rv = match_basic(&pkt, flow);
  TEST_ASSERT_EQUAL_MESSAGE(rv, true,
                            "IPV6_EXTHDR_W match error.");
}
Example #5
0
void
test_match_basic_MPLSMC_BOS(void) {
  struct lagopus_packet pkt;
  struct port port;
  struct flow *flow;
  OS_MBUF *m;
  bool rv;

  /* prepare packet */
  pkt.in_port = &port;
  m = calloc(1, sizeof(*m));
  TEST_ASSERT_NOT_NULL_MESSAGE(m, "calloc error.");
  m->data = &m->dat[128];
  OS_M_PKTLEN(m) = 64;

  /* prepare flow */
  flow = calloc(1, sizeof(struct flow) + 10 * sizeof(struct match));
  TAILQ_INIT(&flow->match_list);

  add_match(&flow->match_list, 2, OFPXMT_OFB_ETH_TYPE << 1,
            0x88, 0x48);
  m->data[12] = 0x88;
  m->data[13] = 0x48;

  /* MPLSMC_BOS */
  add_match(&flow->match_list, 1, OFPXMT_OFB_MPLS_BOS << 1,
            1);
  m->data[14] = 0xff;
  m->data[15] = 0xff;
  m->data[16] = 0xfe;
  m->data[17] = 0xff;
  refresh_match(flow);
  lagopus_packet_init(&pkt, m);
  rv = match_basic(&pkt, flow);
  TEST_ASSERT_EQUAL_MESSAGE(rv, false,
                            "MPLSMC_BOS mismatch(1) error.");
  m->data[14] = 0x00;
  m->data[15] = 0x01;
  m->data[16] = 0x00;
  m->data[17] = 0x00;
  lagopus_packet_init(&pkt, m);
  rv = match_basic(&pkt, flow);
  TEST_ASSERT_EQUAL_MESSAGE(rv, false,
                            "MPLSMC_BOS mismatch(2) error.");
  m->data[14] = 0x00;
  m->data[15] = 0x00;
  m->data[16] = 0x01;
  m->data[17] = 0x00;
  lagopus_packet_init(&pkt, m);
  rv = match_basic(&pkt, flow);
  TEST_ASSERT_EQUAL_MESSAGE(rv, true,
                            "MPLSMC_BOS match error.");
}
Example #6
0
void
test_match_basic_IPV4_SCTP_DST(void) {
  struct lagopus_packet pkt;
  struct port port;
  struct flow *flow;
  OS_MBUF *m;
  bool rv;

  /* prepare packet */
  pkt.in_port = &port;
  m = calloc(1, sizeof(*m));
  TEST_ASSERT_NOT_NULL_MESSAGE(m, "calloc error.");
  m->data = &m->dat[128];
  OS_M_PKTLEN(m) = 64;

  /* prepare flow */
  flow = calloc(1, sizeof(struct flow) + 10 * sizeof(struct match));
  TAILQ_INIT(&flow->match_list);

  add_match(&flow->match_list, 2, OFPXMT_OFB_ETH_TYPE << 1,
            0x08, 0x00);
  m->data[12] = 0x81;
  m->data[13] = 0x00;
  m->data[16] = 0x08;
  m->data[17] = 0x00;
  m->data[18] = 0x45;
  add_match(&flow->match_list, 1, OFPXMT_OFB_IP_PROTO << 1,
            IPPROTO_SCTP);
  m->data[27] = IPPROTO_SCTP;

  /* SCTP_DST */
  add_match(&flow->match_list, 2, OFPXMT_OFB_SCTP_DST << 1,
            0, 80);
  m->data[40] = 80;
  m->data[41] = 0;
  refresh_match(flow);
  lagopus_packet_init(&pkt, m);
  rv = match_basic(&pkt, flow);
  TEST_ASSERT_EQUAL_MESSAGE(rv, false,
                            "SCTP_DST mismatch error.");
  m->data[40] = 0;
  m->data[41] = 80;
  lagopus_packet_init(&pkt, m);
  rv = match_basic(&pkt, flow);
  TEST_ASSERT_EQUAL_MESSAGE(rv, true,
                            "SCTP_DST match error.");
  free(m);
}
void
add_vlan_vid_w_match(struct match_list *match_list, uint16_t vid,
                     uint16_t mask) {
  add_match(match_list, sizeof(vid), (OFPXMT_OFB_VLAN_VID << 1) | 1,
            NBO_BYTE(vid, 0), NBO_BYTE(vid, 1),
            NBO_BYTE(mask, 0), NBO_BYTE(mask, 1));
}
Example #8
0
void
test_match_basic_METADATA_W(void) {
  static const uint8_t metadata[] =
  { 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0 };
  struct lagopus_packet pkt;
  struct port port;
  struct flow *flow;
  OS_MBUF *m;
  bool rv;

  /* prepare packet */
  m = calloc(1, sizeof(*m));
  TEST_ASSERT_NOT_NULL_MESSAGE(m, "calloc error.");
  m->data = &m->dat[128];
  OS_M_PKTLEN(m) = 64;

  /* prepare flow */
  flow = calloc(1, sizeof(struct flow) + 10 * sizeof(struct match));
  TAILQ_INIT(&flow->match_list);

  /* metadata */
  pkt.oob_data.metadata = 0;
  add_match(&flow->match_list, 16, (OFPXMT_OFB_METADATA << 1) + 1,
            0x12, 0x34, 0x56, 0x78, 0x00, 0x00, 0x00, 0x00,
            0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00);
  refresh_match(flow);
  lagopus_packet_init(&pkt, m, &port);
  rv = match_basic(&pkt, flow);
  TEST_ASSERT_EQUAL_MESSAGE(rv, false,
                            "METAADTA_W mismatch error.");
  memcpy(&pkt.oob_data.metadata, metadata, sizeof(pkt.oob_data.metadata));
  rv = match_basic(&pkt, flow);
  TEST_ASSERT_EQUAL_MESSAGE(rv, true,
                            "METADATA_W match error.");
}
Example #9
0
void
test_match_basic_PHY_PORT(void) {
  struct lagopus_packet pkt;
  struct port port;
  struct flow *flow;
  OS_MBUF *m;
  bool rv;

  /* prepare packet */
  memset(&port, 0, sizeof(port));
  m = calloc(1, sizeof(*m));
  TEST_ASSERT_NOT_NULL_MESSAGE(m, "calloc error.");
  m->data = &m->dat[128];
  OS_M_PKTLEN(m) = 64;

  /* prepare flow */
  flow = allocate_test_flow(10 * sizeof(struct match));

  /* Port */
  FLOW_ADD_PORT_MATCH(flow, 4);
  add_match(&flow->match_list, 4, OFPXMT_OFB_IN_PHY_PORT << 1,
            0x00, 0x00, 0x00, 0x04);
  refresh_match(flow);
  lagopus_packet_init(&pkt, m, &port);
  pkt.oob_data.in_port = htonl(4);
  pkt.oob_data.in_phy_port = htonl(1);
  rv = match_basic(&pkt, flow);
  TEST_ASSERT_EQUAL_MESSAGE(rv, false,
                            "IN_PHY_PORT mismatch error.");
  pkt.oob_data.in_phy_port = htonl(4);
  rv = match_basic(&pkt, flow);
  TEST_ASSERT_EQUAL_MESSAGE(rv, true,
                            "IN_PHY_PORT match error.");
}
Example #10
0
void
test_match_basic_IPV4_SCTP_DST(void) {
  struct lagopus_packet *pkt;
  struct port port;
  struct flow *flow;
  OS_MBUF *m;
  bool rv;

  /* prepare packet */
  pkt = alloc_lagopus_packet();
  TEST_ASSERT_NOT_NULL_MESSAGE(pkt, "lagopus_alloc_packet error.");
  m = pkt->mbuf;
  OS_M_APPEND(m, 64);

  /* prepare flow */
  flow = calloc(1, sizeof(struct flow) + 10 * sizeof(struct match));
  TAILQ_INIT(&flow->match_list);

  add_match(&flow->match_list, 2, OFPXMT_OFB_ETH_TYPE << 1,
            0x08, 0x00);
  OS_MTOD(m, uint8_t *)[12] = 0x81;
  OS_MTOD(m, uint8_t *)[13] = 0x00;
  OS_MTOD(m, uint8_t *)[16] = 0x08;
  OS_MTOD(m, uint8_t *)[17] = 0x00;
  OS_MTOD(m, uint8_t *)[18] = 0x45;
  add_match(&flow->match_list, 1, OFPXMT_OFB_IP_PROTO << 1,
            IPPROTO_SCTP);
  OS_MTOD(m, uint8_t *)[27] = IPPROTO_SCTP;

  /* SCTP_DST */
  add_match(&flow->match_list, 2, OFPXMT_OFB_SCTP_DST << 1,
            0, 80);
  OS_MTOD(m, uint8_t *)[40] = 80;
  OS_MTOD(m, uint8_t *)[41] = 0;
  refresh_match(flow);
  lagopus_packet_init(pkt, m, &port);
  rv = match_basic(pkt, flow);
  TEST_ASSERT_EQUAL_MESSAGE(rv, false,
                            "SCTP_DST mismatch error.");
  OS_MTOD(m, uint8_t *)[40] = 0;
  OS_MTOD(m, uint8_t *)[41] = 80;
  lagopus_packet_init(pkt, m, &port);
  rv = match_basic(pkt, flow);
  TEST_ASSERT_EQUAL_MESSAGE(rv, true,
                            "SCTP_DST match error.");
  free(m);
}
Example #11
0
/*
  Return Value:
    - 0 = no match
    - 1 = match
    - -1 = errror
  */
char evaluation(clsvbuff * b,data_person * users)
{
  int id = b->data.clsv_evaluation.id;
  int index = 0;

  for(index = 0;users[id-1].likes[index]!=-1 && index<MAX_LIKES;index++)
  {
      if(users[id-1].likes[index]==b->id_client) /*There is a match*/
      {
          users[id-1].likes[index]=0; /*It can be used for future likes*/

          if(add_match(id,b->id_client,users)==-1)
             return -1;

          if(add_match(b->id_client,id,users)==-1)
             return -1;

          return true;
      }

  }

  /*Now we know that the person of the given id has not evaluated the client*/

  for(index=0;index < MAX_LIKES;index++)
  {
      if(users[b->id_client-1].likes[index]==0)
      {
          users[b->id_client-1].likes[index]=id;
          return false;
      }
      else if (users[b->id_client-1].likes[index]==-1)
      {
          users[b->id_client-1].likes[index]=id;
          if(index+1!=MAX_LIKES)
              users[b->id_client-1].likes[index+1]=-1;
          return false;
      }

  }

  /*There is no space to save the like*/

  return -1;

}
void
add_tunnelid_w_match(struct match_list *match_list, uint64_t id,
                     uint64_t mask) {
  add_match(match_list, sizeof(id), (OFPXMT_OFB_TUNNEL_ID << 1) | 1,
            NBO_BYTE(id, 0), NBO_BYTE(id, 1), NBO_BYTE(id, 2), NBO_BYTE(id, 3),
            NBO_BYTE(id, 4), NBO_BYTE(id, 5), NBO_BYTE(id, 6), NBO_BYTE(id, 7),
            NBO_BYTE(mask, 0), NBO_BYTE(mask, 1), NBO_BYTE(mask, 2), NBO_BYTE(mask, 3),
            NBO_BYTE(mask, 4), NBO_BYTE(mask, 5), NBO_BYTE(mask, 6), NBO_BYTE(mask, 7));
}
void
add_metadata_w_match(struct match_list *match_list, uint64_t md,
                     uint64_t mask) {
  add_match(match_list, 2 * sizeof(md), (OFPXMT_OFB_METADATA << 1) | 1,
            NBO_BYTE(md, 0), NBO_BYTE(md, 1), NBO_BYTE(md, 2), NBO_BYTE(md, 3),
            NBO_BYTE(md, 4), NBO_BYTE(md, 5), NBO_BYTE(md, 6), NBO_BYTE(md, 7),
            NBO_BYTE(mask, 0), NBO_BYTE(mask, 1), NBO_BYTE(mask, 2), NBO_BYTE(mask, 3),
            NBO_BYTE(mask, 4), NBO_BYTE(mask, 5), NBO_BYTE(mask, 6), NBO_BYTE(mask, 7));
}
Example #14
0
void ListParser::init()
{
  add_match("MODULE_DEF", &proc_module_def);
  add_match("MODULE_BEGIN", &proc_module_begin);
  add_match("MODULE_END", &proc_module_end);
  add_match("SWITCH_BEGIN", &proc_switch_begin);
  add_match("SWITCH_END", &proc_switch_end);
  add_match("DEF", &proc_unittest_def);
  add_match("BEGIN", &proc_unittest_begin);
  add_match("END", &proc_unittest_end);
}
Example #15
0
void
test_match_basic_PBB_ISID_W(void) {
  struct lagopus_packet *pkt;
  struct port port;
  struct flow *flow;
  OS_MBUF *m;
  bool rv;

  /* prepare packet */
  pkt = alloc_lagopus_packet();
  TEST_ASSERT_NOT_NULL_MESSAGE(pkt, "lagopus_alloc_packet error.");
  m = PKT2MBUF(pkt);
  OS_M_APPEND(m, 64);

  /* prepare flow */
  flow = calloc(1, sizeof(struct flow) + 10 * sizeof(struct match));
  TAILQ_INIT(&flow->match_list);

#ifndef PBB_IS_VLAN
  add_match(&flow->match_list, 2, OFPXMT_OFB_ETH_TYPE << 1,
            0x88, 0xe7);
#endif
  OS_MTOD(m, uint8_t *)[12] = 0x88;
  OS_MTOD(m, uint8_t *)[13] = 0xe7;
  add_match(&flow->match_list, 6, (OFPXMT_OFB_PBB_ISID << 1) + 1,
            0x5a, 0xc3, 0x00, 0xff, 0xff, 0x00);
  refresh_match(flow);
  lagopus_packet_init(pkt, m, &port);
  rv = match_basic(pkt, flow);
  TEST_ASSERT_EQUAL_MESSAGE(rv, false,
                            "PBB_ISID_W mismatch(1) error.");
  OS_MTOD(m, uint8_t *)[15] = 0x3c;
  OS_MTOD(m, uint8_t *)[16] = 0xc3;
  OS_MTOD(m, uint8_t *)[17] = 0x5a;
  rv = match_basic(pkt, flow);
  TEST_ASSERT_EQUAL_MESSAGE(rv, false,
                            "PBB_ISID_W mismatch(2) error.");
  OS_MTOD(m, uint8_t *)[15] = 0x5a;
  OS_MTOD(m, uint8_t *)[16] = 0xc3;
  OS_MTOD(m, uint8_t *)[17] = 0x3c;
  rv = match_basic(pkt, flow);
  TEST_ASSERT_EQUAL_MESSAGE(rv, true,
                            "PBB_ISID_W match error.");
}
Example #16
0
void
test_match_basic_PBB_ISID_W(void) {
  struct lagopus_packet pkt;
  struct port port;
  struct flow *flow;
  OS_MBUF *m;
  bool rv;

  /* prepare packet */
  m = calloc(1, sizeof(*m));
  TEST_ASSERT_NOT_NULL_MESSAGE(m, "calloc error.");
  m->data = &m->dat[128];
  OS_M_PKTLEN(m) = 64;

  /* prepare flow */
  flow = calloc(1, sizeof(struct flow) + 10 * sizeof(struct match));
  TAILQ_INIT(&flow->match_list);

#ifndef PBB_IS_VLAN
  add_match(&flow->match_list, 2, OFPXMT_OFB_ETH_TYPE << 1,
            0x88, 0xe7);
#endif
  m->data[12] = 0x88;
  m->data[13] = 0xe7;
  add_match(&flow->match_list, 6, (OFPXMT_OFB_PBB_ISID << 1) + 1,
            0x5a, 0xc3, 0x00, 0xff, 0xff, 0x00);
  refresh_match(flow);
  lagopus_packet_init(&pkt, m, &port);
  rv = match_basic(&pkt, flow);
  TEST_ASSERT_EQUAL_MESSAGE(rv, false,
                            "PBB_ISID_W mismatch(1) error.");
  m->data[15] = 0x3c;
  m->data[16] = 0xc3;
  m->data[17] = 0x5a;
  rv = match_basic(&pkt, flow);
  TEST_ASSERT_EQUAL_MESSAGE(rv, false,
                            "PBB_ISID_W mismatch(2) error.");
  m->data[15] = 0x5a;
  m->data[16] = 0xc3;
  m->data[17] = 0x3c;
  rv = match_basic(&pkt, flow);
  TEST_ASSERT_EQUAL_MESSAGE(rv, true,
                            "PBB_ISID_W match error.");
}
Example #17
0
void
test_match_basic_IPV6_FLABEL(void) {
  struct lagopus_packet pkt;
  struct port port;
  struct flow *flow;
  OS_MBUF *m;
  bool rv;

  /* prepare packet */
  pkt.in_port = &port;
  m = calloc(1, sizeof(*m));
  TEST_ASSERT_NOT_NULL_MESSAGE(m, "calloc error.");
  m->data = &m->dat[128];
  OS_M_PKTLEN(m) = 64;

  /* prepare flow */
  flow = calloc(1, sizeof(struct flow) + 10 * sizeof(struct match));
  TAILQ_INIT(&flow->match_list);

  add_match(&flow->match_list, 2, OFPXMT_OFB_ETH_TYPE << 1,
            0x86, 0xdd);
  m->data[12] = 0x86;
  m->data[13] = 0xdd;
  m->data[15] = 0x00;
  m->data[16] = 0x12;
  m->data[17] = 0x34;
  add_match(&flow->match_list, 4, OFPXMT_OFB_IPV6_FLABEL << 1,
            0x00, 0x01, 0x23, 0x45);
  refresh_match(flow);
  lagopus_packet_init(&pkt, m);
  rv = match_basic(&pkt, flow);
  TEST_ASSERT_EQUAL_MESSAGE(rv, false,
                            "IPV6_FLABEL mismatch error.");
  m->data[15] = 0x01;
  m->data[16] = 0x23;
  m->data[17] = 0x45;
  lagopus_packet_init(&pkt, m);
  rv = match_basic(&pkt, flow);
  TEST_ASSERT_EQUAL_MESSAGE(rv, true,
                            "IPV6_FLABEL match error.");
}
Example #18
0
static void username_tab_completion(char *ud, char *with_shash_flg)
{
	struct passwd *entry;
	int userlen;

	ud++;                           /* ~user/... to user/... */
	userlen = strlen(ud);

	if (with_shash_flg) {           /* "~/..." or "~user/..." */
		char *sav_ud = ud - 1;
		char *home = NULL;
		char *temp;

		if (*ud == '/') {       /* "~/..."     */
			home = home_pwd_buf;
		} else {
			/* "~user/..." */
			temp = strchr(ud, '/');
			*temp = 0;              /* ~user\0 */
			entry = getpwnam(ud);
			*temp = '/';            /* restore ~user/... */
			ud = temp;
			if (entry)
				home = entry->pw_dir;
		}
		if (home) {
			if ((userlen + strlen(home) + 1) < MAX_LINELEN) {
				char temp2[MAX_LINELEN];     /* argument size */

				/* /home/user/... */
				sprintf(temp2, "%s%s", home, ud);
				strcpy(sav_ud, temp2);
			}
		}
	} else {
		/* "~[^/]*" */
		/* Using _r function to avoid pulling in static buffers */
		char line_buff[256];
		struct passwd pwd;
		struct passwd *result;

		setpwent();
		while (!getpwent_r(&pwd, line_buff, sizeof(line_buff), &result)) {
			/* Null usernames should result in all users as possible completions. */
			if (/*!userlen || */ strncmp(ud, pwd.pw_name, userlen) == 0) {
				add_match(xasprintf("~%s/", pwd.pw_name));
			}
		}
		endpwent();
	}
}
Example #19
0
void
test_match_basic_IPV4_IP_ECN(void) {
  struct lagopus_packet pkt;
  struct port port;
  struct flow *flow;
  OS_MBUF *m;
  bool rv;

  /* prepare packet */
  pkt.in_port = &port;
  m = calloc(1, sizeof(*m));
  TEST_ASSERT_NOT_NULL_MESSAGE(m, "calloc error.");
  m->data = &m->dat[128];
  OS_M_PKTLEN(m) = 64;

  /* prepare flow */
  flow = calloc(1, sizeof(struct flow) + 10 * sizeof(struct match));
  TAILQ_INIT(&flow->match_list);

  add_match(&flow->match_list, 2, OFPXMT_OFB_ETH_TYPE << 1,
            0x08, 0x00);
  refresh_match(flow);
  m->data[12] = 0x08;
  m->data[13] = 0x00;
  m->data[14] = 0x45;
  add_match(&flow->match_list, 1, OFPXMT_OFB_IP_ECN << 1,
            0x3);
  m->data[15] = 0xcc;
  refresh_match(flow);
  lagopus_packet_init(&pkt, m);
  rv = match_basic(&pkt, flow);
  TEST_ASSERT_EQUAL_MESSAGE(rv, false,
                            "IP_ECN mismatch error.");
  m->data[15] = 0x03;
  rv = match_basic(&pkt, flow);
  TEST_ASSERT_EQUAL_MESSAGE(rv, true,
                            "IP_ECN match error.");
}
Example #20
0
void
test_match_basic_IPV4_IP_ECN(void) {
  struct lagopus_packet *pkt;
  struct port port;
  struct flow *flow;
  OS_MBUF *m;
  bool rv;

  /* prepare packet */
  pkt = alloc_lagopus_packet();
  TEST_ASSERT_NOT_NULL_MESSAGE(pkt, "lagopus_alloc_packet error.");
  m = pkt->mbuf;
  OS_M_APPEND(m, 64);

  /* prepare flow */
  flow = calloc(1, sizeof(struct flow) + 10 * sizeof(struct match));
  TAILQ_INIT(&flow->match_list);

  add_match(&flow->match_list, 2, OFPXMT_OFB_ETH_TYPE << 1,
            0x08, 0x00);
  refresh_match(flow);
  OS_MTOD(m, uint8_t *)[12] = 0x08;
  OS_MTOD(m, uint8_t *)[13] = 0x00;
  OS_MTOD(m, uint8_t *)[14] = 0x45;
  add_match(&flow->match_list, 1, OFPXMT_OFB_IP_ECN << 1,
            0x3);
  OS_MTOD(m, uint8_t *)[15] = 0xcc;
  refresh_match(flow);
  lagopus_packet_init(pkt, m, &port);
  rv = match_basic(pkt, flow);
  TEST_ASSERT_EQUAL_MESSAGE(rv, false,
                            "IP_ECN mismatch error.");
  OS_MTOD(m, uint8_t *)[15] = 0x03;
  rv = match_basic(pkt, flow);
  TEST_ASSERT_EQUAL_MESSAGE(rv, true,
                            "IP_ECN match error.");
}
Example #21
0
File: fixed.c Project: julp/ugrep
UBool binary_fwd_n(
    UBreakIterator *ubrk,
    const UString *pattern,
    const UString *subject,
    DArray *array, /* NULL to skip n matches */
    int32_t n,
    int32_t *r
) {
    UChar *m;
    int32_t pos;

    pos = *r;
//     *r = USEARCH_DONE;
    while (n > 0 && NULL != (m = u_strFindFirst(subject->ptr + pos, subject->len - pos, pattern->ptr, pattern->len))) {
        pos = m - subject->ptr;
        if (NULL == ubrk || (ubrk_isBoundary(ubrk, pos) && ubrk_isBoundary(ubrk, pos + pattern->len))) {
            --n;
            if (NULL != array) {
//                 debug(">%.*S<", pos - *r, subject->ptr + *r);
                add_match(array, subject, *r, pos);
            }
            *r = pos + pattern->len; // TODO: don't repeat following pos += pattern->len;
        }
        pos += pattern->len;
    }
    if (0 == n) {
        *r = pos;
        return TRUE;
    } else {
        if (NULL != array) {
//             debug(">%.*S<", pos - *r, subject->ptr + *r);
            add_match(array, subject, *r, subject->len);
        }
        *r = USEARCH_DONE;
        return FALSE;
    }
}
Example #22
0
/*
 * Similar wierd recursion to nv_constructor() (qv)
 */
local void
gen_match_constr(int level, Path *here_ptr, int arity, Expr *pattern)
{
	if (pattern->e_class == E_CONS) {
		if (pattern->e_const == succ) {
			add_match(level, *here_ptr, NUMCASE, GREATER);
			*here_ptr = p_push(P_PRED, *here_ptr);
		} else {
			add_match(level, *here_ptr,
				num_cases(pattern->e_const),
				pattern->e_const->c_index);
			*here_ptr = p_push(P_STRIP, *here_ptr);
		}
	} else {
		ASSERT( pattern->e_class == E_APPLY );
		gen_match_constr(level, here_ptr, arity+1, pattern->e_func);
		if (arity > 0) {
			gen_matches(level, p_push(P_LEFT, *here_ptr),
				pattern->e_arg);
			*here_ptr = p_push(P_RIGHT, *here_ptr);
		} else	/* last argument */
			gen_matches(level, *here_ptr, pattern->e_arg);
	}
}
Example #23
0
static void username_tab_completion(char *ud, char *with_shash_flg)
{
	struct passwd *entry;
	int userlen;

	ud++;                           /* ~user/... to user/... */
	userlen = strlen(ud);

	if (with_shash_flg) {           /* "~/..." or "~user/..." */
		char *sav_ud = ud - 1;
		char *home = 0;
		char *temp;

		if (*ud == '/') {       /* "~/..."     */
			home = home_pwd_buf;
		} else {
			/* "~user/..." */
			temp = strchr(ud, '/');
			*temp = 0;              /* ~user\0 */
			entry = getpwnam(ud);
			*temp = '/';            /* restore ~user/... */
			ud = temp;
			if (entry)
				home = entry->pw_dir;
		}
		if (home) {
			if ((userlen + strlen(home) + 1) < BUFSIZ) {
				char temp2[BUFSIZ];     /* argument size */

				/* /home/user/... */
				sprintf(temp2, "%s%s", home, ud);
				strcpy(sav_ud, temp2);
			}
		}
	} else {
		/* "~[^/]*" */
		setpwent();

		while ((entry = getpwent()) != NULL) {
			/* Null usernames should result in all users as possible completions. */
			if ( /*!userlen || */ !strncmp(ud, entry->pw_name, userlen)) {
				add_match(xasprintf("~%s/", entry->pw_name));
			}
		}

		endpwent();
	}
}
Example #24
0
static int add_matches(sd_journal *j, char **matches) {
        char **match;
        int r;

        r = sd_journal_add_match(j, "MESSAGE_ID=" SD_MESSAGE_COREDUMP_STR, 0);
        if (r < 0)
                return log_error_errno(r, "Failed to add match \"%s\": %m", "MESSAGE_ID=" SD_MESSAGE_COREDUMP_STR);

        r = sd_journal_add_match(j, "MESSAGE_ID=" SD_MESSAGE_BACKTRACE_STR, 0);
        if (r < 0)
                return log_error_errno(r, "Failed to add match \"%s\": %m", "MESSAGE_ID=" SD_MESSAGE_BACKTRACE_STR);

        STRV_FOREACH(match, matches) {
                r = add_match(j, *match);
                if (r < 0)
                        return r;
        }
Example #25
0
void MatchSet :: read_from_file( string filename ){
    ifstream input_file( filename.c_str() );
    size_t num_matches;
    input_file >> num_matches;
    for( size_t i = 0; i < num_matches; i++ ){
        PointT pt_c;
        PointT pt_r;
        float strength;
        int ref_idx;
        input_file  >>  pt_c.first  >> pt_c.second 
                    >>  pt_r.first  >> pt_r.second
                    >>  strength    >> ref_idx;
        add_match( pt_c, pt_r, strength, ref_idx );
    }
    input_file.close();

}
Example #26
0
static void
make_match(struct match_list *match_list, int n, ...) {
  va_list ap;

  int match_type;
  uint32_t match_arg, match_mask;
  int nbytes, i;

  va_start(ap, n);
  for (i = 0; i < n; i++) {
    nbytes = va_arg(ap, int);
    match_type = va_arg(ap, int);
    match_arg = va_arg(ap, uint32_t);
    if (match_type & 1) {
      match_mask = va_arg(ap, uint32_t);
      switch (nbytes) {
        case 8:
          add_match(match_list, nbytes, match_type,
                    (match_arg >> 24) & 0xff,
                    (match_arg >> 16) & 0xff,
                    (match_arg >>  8) & 0xff,
                    match_arg & 0xff,
                    (match_mask >> 24) & 0xff,
                    (match_mask >> 16) & 0xff,
                    (match_mask >>  8) & 0xff,
                    match_mask & 0xff);
          break;

        case 4:
          add_match(match_list, nbytes, match_type,
                    (match_arg >>  8) & 0xff,
                    match_arg & 0xff,
                    (match_mask >>  8) & 0xff,
                    match_mask & 0xff);
          break;

        case 2:
          add_match(match_list, nbytes, match_type,
                    match_arg & 0xff,
                    match_mask & 0xff);
          break;
      }
    } else {
      switch (nbytes) {
Example #27
0
void
test_match_basic_VLAN_VID_W(void) {
  struct lagopus_packet *pkt;
  struct port port;
  struct flow *flow;
  OS_MBUF *m;
  bool rv;

  /* prepare packet */
  pkt = alloc_lagopus_packet();
  TEST_ASSERT_NOT_NULL_MESSAGE(pkt, "lagopus_alloc_packet error.");
  m = PKT2MBUF(pkt);
  OS_M_APPEND(m, 64);

  /* prepare flow */
  flow = calloc(1, sizeof(struct flow) + 10 * sizeof(struct match));
  TAILQ_INIT(&flow->match_list);

  /* VLAN VID_NONE */
  add_match(&flow->match_list, 4, (OFPXMT_OFB_VLAN_VID << 1) + 1,
            0x10, 0x00, 0x10, 0x00);
  refresh_match(flow);
  OS_MTOD(m, uint8_t *)[12] = 0x08;
  OS_MTOD(m, uint8_t *)[13] = 0x00;
  lagopus_packet_init(pkt, m, &port);
  rv = match_basic(pkt, flow);
  TEST_ASSERT_EQUAL_MESSAGE(rv, false,
                            "VLAN_VID_W mismatch error.");
  OS_MTOD(m, uint8_t *)[12] = 0x81;
  OS_MTOD(m, uint8_t *)[13] = 0x00;
  OS_MTOD(m, uint8_t *)[14] = 0x00;
  OS_MTOD(m, uint8_t *)[15] = 0xff;
  lagopus_packet_init(pkt, m, &port);
  rv = match_basic(pkt, flow);
  TEST_ASSERT_EQUAL_MESSAGE(rv, true,
                            "VLAN VID_W match error.");
  free(m);
}
Example #28
0
void
test_match_basic_IPV6_DST_W(void) {
  struct lagopus_packet pkt;
  struct port port;
  struct flow *flow;
  OS_MBUF *m;
  bool rv;
  int i;

  /* prepare packet */
  pkt.in_port = &port;
  m = calloc(1, sizeof(*m));
  TEST_ASSERT_NOT_NULL_MESSAGE(m, "calloc error.");
  m->data = &m->dat[128];
  OS_M_PKTLEN(m) = 64;

  /* prepare flow */
  flow = calloc(1, sizeof(struct flow) + 10 * sizeof(struct match));
  TAILQ_INIT(&flow->match_list);

  add_match(&flow->match_list, 2, OFPXMT_OFB_ETH_TYPE << 1,
            0x86, 0xdd);
  m->data[12] = 0x86;
  m->data[13] = 0xdd;
  i = 38;
  m->data[i++] = 0x20;
  m->data[i++] = 0x01;
  m->data[i++] = 0x20;
  m->data[i++] = 0xff;
  m->data[i++] = 0x00;
  m->data[i++] = 0x00;
  m->data[i++] = 0x10;
  m->data[i++] = 0x20;
  m->data[i++] = 0x11;
  m->data[i++] = 0xe1;
  m->data[i++] = 0x50;
  m->data[i++] = 0x89;
  m->data[i++] = 0xbf;
  m->data[i++] = 0xc6;
  m->data[i++] = 0x43;
  m->data[i++] = 0x11;
  lagopus_packet_init(&pkt, m);
  add_match(&flow->match_list, 32, (OFPXMT_OFB_IPV6_DST << 1) + 1,
            0x20, 0x01, 0x00, 0x00, 0xe0, 0x45, 0x22, 0xeb,
            0x09, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00,
            0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
            0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00);
  refresh_match(flow);
  rv = match_basic(&pkt, flow);
  TEST_ASSERT_EQUAL_MESSAGE(rv, false,
                            "IPV6_DST_W mismatch error.");
  i = 38;
  m->data[i++] = 0x20;
  m->data[i++] = 0x01;
  m->data[i++] = 0x00;
  m->data[i++] = 0x00;
  m->data[i++] = 0xe0;
  m->data[i++] = 0x45;
  m->data[i++] = 0x22;
  m->data[i++] = 0xeb;
  m->data[i++] = 0x09;
  m->data[i++] = 0x00;
  m->data[i++] = 0x00;
  m->data[i++] = 0x08;
  m->data[i++] = 0xdc;
  m->data[i++] = 0x18;
  m->data[i++] = 0x94;
  m->data[i++] = 0xad;
  rv = match_basic(&pkt, flow);
  TEST_ASSERT_EQUAL_MESSAGE(rv, true,
                            "IPV6_DST_W match error.");
}
Example #29
0
static int parse_argv(int argc, char *argv[], Set *matches) {
        enum {
                ARG_VERSION = 0x100,
                ARG_NO_PAGER,
                ARG_NO_LEGEND,
        };

        int r, c;

        static const struct option options[] = {
                { "help",         no_argument,       NULL, 'h'           },
                { "version" ,     no_argument,       NULL, ARG_VERSION   },
                { "no-pager",     no_argument,       NULL, ARG_NO_PAGER  },
                { "no-legend",    no_argument,       NULL, ARG_NO_LEGEND },
                { "output",       required_argument, NULL, 'o'           },
                { "field",        required_argument, NULL, 'F'           },
                { "directory",    required_argument, NULL, 'D'           },
                {}
        };

        assert(argc >= 0);
        assert(argv);

        while ((c = getopt_long(argc, argv, "ho:F:1D:", options, NULL)) >= 0)
                switch(c) {

                case 'h':
                        arg_action = ACTION_NONE;
                        help();
                        return 0;

                case ARG_VERSION:
                        arg_action = ACTION_NONE;
                        puts(PACKAGE_STRING);
                        puts(SYSTEMD_FEATURES);
                        return 0;

                case ARG_NO_PAGER:
                        arg_no_pager = true;
                        break;

                case ARG_NO_LEGEND:
                        arg_no_legend = true;
                        break;

                case 'o':
                        if (arg_output) {
                                log_error("cannot set output more than once");
                                return -EINVAL;
                        }

                        arg_output = fopen(optarg, "we");
                        if (!arg_output)
                                return log_error_errno(errno, "writing to '%s': %m", optarg);

                        break;

                case 'F':
                        if (arg_field) {
                                log_error("cannot use --field/-F more than once");
                                return -EINVAL;
                        }
                        arg_field = optarg;
                        break;

                case '1':
                        arg_one = true;
                        break;

                case 'D':
                        arg_directory = optarg;
                        break;

                case '?':
                        return -EINVAL;

                default:
                        assert_not_reached("Unhandled option");
                }

        if (optind < argc) {
                const char *cmd = argv[optind++];
                if (streq(cmd, "list"))
                        arg_action = ACTION_LIST;
                else if (streq(cmd, "dump"))
                        arg_action = ACTION_DUMP;
                else if (streq(cmd, "gdb"))
                        arg_action = ACTION_GDB;
                else if (streq(cmd, "info"))
                        arg_action = ACTION_INFO;
                else {
                        log_error("Unknown action '%s'", cmd);
                        return -EINVAL;
                }
        }

        if (arg_field && arg_action != ACTION_LIST) {
                log_error("Option --field/-F only makes sense with list");
                return -EINVAL;
        }

        while (optind < argc) {
                r = add_match(matches, argv[optind]);
                if (r != 0)
                        return r;
                optind++;
        }

        return 0;
}
Example #30
0
static void exe_n_cwd_tab_completion(char *command, int type)
{
	DIR *dir;
	struct dirent *next;
	char dirbuf[MAX_LINELEN];
	struct stat st;
	char *path1[1];
	char **paths = path1;
	int npaths;
	int i;
	char *found;
	char *pfind = strrchr(command, '/');

	npaths = 1;
	path1[0] = (char*)".";

	if (pfind == NULL) {
		/* no dir, if flags==EXE_ONLY - get paths, else "." */
		npaths = path_parse(&paths, type);
		pfind = command;
	} else {
		/* dirbuf = ".../.../.../" */
		safe_strncpy(dirbuf, command, (pfind - command) + 2);
#if ENABLE_FEATURE_USERNAME_COMPLETION
		if (dirbuf[0] == '~')   /* ~/... or ~user/... */
			username_tab_completion(dirbuf, dirbuf);
#endif
		paths[0] = dirbuf;
		/* point to 'l' in "..../last_component" */
		pfind++;
	}

	for (i = 0; i < npaths; i++) {
		dir = opendir(paths[i]);
		if (!dir)                       /* Don't print an error */
			continue;

		while ((next = readdir(dir)) != NULL) {
			int len1;
			const char *str_found = next->d_name;

			/* matched? */
			if (strncmp(str_found, pfind, strlen(pfind)))
				continue;
			/* not see .name without .match */
			if (*str_found == '.' && *pfind == 0) {
				if (NOT_LONE_CHAR(paths[i], '/') || str_found[1])
					continue;
				str_found = ""; /* only "/" */
			}
			found = concat_path_file(paths[i], str_found);
			/* hmm, remover in progress? */
			if (stat(found, &st) < 0)
				goto cont;
			/* find with dirs? */
			if (paths[i] != dirbuf)
				strcpy(found, next->d_name);    /* only name */

			len1 = strlen(found);
			found = xrealloc(found, len1 + 2);
			found[len1] = '\0';
			found[len1+1] = '\0';

			if (S_ISDIR(st.st_mode)) {
				/* name is directory      */
				if (found[len1-1] != '/') {
					found[len1] = '/';
				}
			} else {
				/* not put found file if search only dirs for cd */
				if (type == FIND_DIR_ONLY)
					goto cont;
			}
			/* Add it to the list */
			add_match(found);
			continue;
 cont:
			free(found);
		}
		closedir(dir);
	}
	if (paths != path1) {
		free(paths[0]);                 /* allocated memory only in first member */
		free(paths);
	}
}