Revision 4b03f64b nest/a-path.c

View differences:

nest/a-path.c
19 19
{
20 20
  struct adata *newa;
21 21

  
22
  if (olda->length && olda->data[0] == 2 && olda->data[1] < 255) /* Starting with sequence => just prepend the AS number */
22
  if (olda->length && olda->data[0] == AS_PATH_SEQUENCE &&
23
      olda->data[1] < 255) /* Starting with sequence => just prepend the AS number */
23 24
    {
24 25
      newa = lp_alloc(pool, sizeof(struct adata) + olda->length + 2);
25 26
      newa->length = olda->length + 2;
......
90 91
  u8 *q = p+path->length;
91 92
  int len;
92 93

  
93
  while (p<q) {
94
    switch (*p++) {
95
    case 1: len = *p++; res++;    p += 2*len; break;
96
    case 2: len = *p++; res+=len; p += 2*len; break;
97
    default: bug("This should not be in path");
94
  while (p<q)
95
    {
96
      switch (*p++)
97
	{
98
	case AS_PATH_SET:      len = *p++; res++;    p += 2*len; break;
99
	case AS_PATH_SEQUENCE: len = *p++; res+=len; p += 2*len; break;
100
	default: bug("as_path_getlen: Invalid path segment");
101
	}
98 102
    }
99
  }
100 103
  return res;
101 104
}
102 105

  
103 106
#define MASK_PLUS do { mask = mask->next; if (!mask) return next == q; \
104
		       asterix = (mask->val == PM_ANY); \
105
                       if (asterix) { mask = mask->next; if (!mask) { return 1; } } \
107
		       asterisk = (mask->val == PM_ANY); \
108
                       if (asterisk) { mask = mask->next; if (!mask) { return 1; } } \
106 109
		       } while(0)
107 110

  
108 111
int
109 112
as_path_match(struct adata *path, struct f_path_mask *mask)
110 113
{
111 114
  int i;
112
  int asterix = 0;
115
  int asterisk = 0;
113 116
  u8 *p = path->data;
114 117
  u8 *q = p+path->length;
115 118
  int len;
116 119
  u8 *next;
117 120

  
118
  asterix = (mask->val == PM_ANY);
119
  if (asterix) { mask = mask->next; if (!mask) { return 1; } }
121
  asterisk = (mask->val == PM_ANY);
122
  if (asterisk)
123
    { mask = mask->next; if (!mask) return 1; }
120 124

  
121 125
  while (p<q) {
122 126
    switch (*p++) {
123
    case 1:	/* This is a set */
127
    case AS_PATH_SET:
124 128
      len = *p++;
125 129
      {
126 130
	u8 *p_save = p;
......
128 132
      retry:
129 133
	p = p_save;
130 134
	for (i=0; i<len; i++) {
131
	  if (asterix && (get_u16(p) == mask->val)) {
135
	  if (asterisk && (get_u16(p) == mask->val)) {
132 136
	    MASK_PLUS;
133 137
	    goto retry;
134 138
	  }
135
	  if (!asterix && (get_u16(p) == mask->val)) {
139
	  if (!asterisk && (get_u16(p) == mask->val)) {
136 140
	    p = next;
137 141
	    MASK_PLUS;
138 142
	    goto okay;
139 143
	  }
140 144
	  p+=2;
141 145
	}
142
	if (!asterix)
146
	if (!asterisk)
143 147
	  return 0;
144 148
      okay:
145 149
      }
146 150
      break;
147 151

  
148
    case 2:	/* This is a sequence */
152
    case AS_PATH_SEQUENCE:
149 153
      len = *p++;
150 154
      for (i=0; i<len; i++) {
151 155
	next = p+2;
152
	if (asterix && (get_u16(p) == mask->val))
156
	if (asterisk && (get_u16(p) == mask->val))
153 157
	  MASK_PLUS;
154
	else if (!asterix) {
158
	else if (!asterisk) {
155 159
	  if (get_u16(p) != mask->val)
156 160
	    return 0;
157 161
	  MASK_PLUS;
......
161 165
      break;
162 166

  
163 167
    default:
164
      bug("This should not be in path");
168
      bug("as_path_match: Invalid path component");
165 169
    }
166 170
  }
167 171
  return 0;

Also available in: Unified diff